0
0
Laravelframework~10 mins

Raw PHP in Blade (@php) in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a raw PHP block in a Blade template.

Laravel
@[1]
    $message = 'Hello from PHP!';
@endphp
Drag options to blanks, or click blank then click option'
A@phpstart
B@phpopen
C@phpblock
D@php
Attempts:
3 left
💡 Hint
Common Mistakes
Using @phpstart or @phpblock which are not valid Blade directives.
Forgetting the @ symbol before php.
2fill in blank
medium

Complete the code to end a raw PHP block in a Blade template.

Laravel
@php
    $count = 5;
[1]
Drag options to blanks, or click blank then click option'
A@stopphp
B@phpend
C@endphp
D@closephp
Attempts:
3 left
💡 Hint
Common Mistakes
Using @phpend or @stopphp which are not valid Blade directives.
Forgetting to close the PHP block.
3fill in blank
hard

Fix the error in the Blade template to correctly embed raw PHP code.

Laravel
@php
    echo 'Count is: ' . [1];
@endphp
Drag options to blanks, or click blank then click option'
Acount()
B$count
Ccount_var
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without $ inside PHP blocks.
Using function calls like count() when variable is intended.
4fill in blank
hard

Fill both blanks to create a Blade template that sets a PHP variable and echoes it.

Laravel
@[1]
    $name = 'Laravel';
    echo 'Welcome to ' . [2];
@endphp
Drag options to blanks, or click blank then click option'
Aphp
B$name
Cname
Dphpstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' without $ inside PHP.
Using invalid directive like @phpstart.
5fill in blank
hard

Fill all three blanks to create a Blade template that declares two PHP variables and echoes their sum.

Laravel
@[1]
    $a = 10;
    $b = 20;
    echo [2] + [3];
@endphp
Drag options to blanks, or click blank then click option'
Aphp
B$a
C$b
Dphpblock
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without $ inside PHP.
Using invalid directive like @phpblock.