0
0
Laravelframework~10 mins

Laravel vs other PHP frameworks - Interactive Practice

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

Complete the code to create a new Laravel route that returns a welcome view.

Laravel
Route::[1]('/', function () {
    return view('welcome');
});
Drag options to blanks, or click blank then click option'
Apost
Bget
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for displaying a page.
Confusing HTTP methods for routes.
2fill in blank
medium

Complete the code to use Eloquent ORM to get all users from the database.

Laravel
$users = User::[1]();
Drag options to blanks, or click blank then click option'
Aall
Bfind
Cget
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() without an ID parameter.
Using get() without a query builder.
3fill in blank
hard

Fix the error in the middleware registration in Laravel's HTTP kernel.

Laravel
'middleware' => [
    [1]::class,
],
Drag options to blanks, or click blank then click option'
AAuthenticate
Bauth
CAuthMiddleware
DAuthenticateMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase strings instead of class names.
Adding 'Middleware' suffix incorrectly.
4fill in blank
hard

Fill both blanks to define a Laravel controller method that returns a JSON response with all posts.

Laravel
public function index() {
    $posts = Post::[1]();
    return response()->[2]($posts);
}
Drag options to blanks, or click blank then click option'
Aall
Bjson
Cview
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using all() without query builder context.
Returning a view instead of JSON.
5fill in blank
hard

Fill all three blanks to create a Laravel Blade template loop that displays each user's name inside an <li> element.

Laravel
<ul>
@foreach($users as [1])
    <li>{{ [2]->[3] }}</li>
@endforeach
</ul>
Drag options to blanks, or click blank then click option'
A$user
B$item
Cname
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names inside the loop.
Using a wrong property name like 'username' if not defined.