0
0
Laravelframework~20 mins

First Laravel application - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Beginner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What does this route return?
Consider this Laravel route defined in routes/web.php. What will the browser display when you visit /hello?
Laravel
<?php

use Illuminate\Support\Facades\Route;

Route::get('/hello', function () {
    return 'Hello, Laravel!';
});
AThe text 'Hello, Laravel!'
BA blank page
CA JSON object with key 'message' and value 'Hello, Laravel!'
DA 404 Not Found error
Attempts:
2 left
💡 Hint
Look at what the route's closure returns directly.
📝 Syntax
intermediate
1:30remaining
Identify the syntax error in this controller method
Look at this Laravel controller method. Which option correctly identifies the syntax error?
Laravel
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WelcomeController extends Controller
{
    public function index()
    {
        return view('welcome');
    }
}
AWrong namespace declaration
BMissing parentheses in method declaration
CIncorrect use statement for Request
DMissing semicolon after return statement
Attempts:
2 left
💡 Hint
Check the end of the return statement line.
state_output
advanced
2:00remaining
What is the output of this Blade template?
Given this Blade template resources/views/greeting.blade.php, what will be rendered in the browser?
Laravel
@php
    $name = 'Alice';
@endphp

<h1>Hello, {{ $name }}!</h1>
@if(strlen($name) > 3)
    <p>Welcome to Laravel.</p>
@endif
A<h1>Hello, {{ $name }}!</h1><p>Welcome to Laravel.</p>
B<h1>Hello, Alice!</h1>
C<h1>Hello, Alice!</h1><p>Welcome to Laravel.</p>
DSyntax error in Blade template
Attempts:
2 left
💡 Hint
Check how Blade outputs variables and evaluates conditions.
🔧 Debug
advanced
2:00remaining
Why does this route cause a 500 error?
This route causes a server error when accessed. What is the cause?
Laravel
<?php

use Illuminate\Support\Facades\Route;

Route::get('/user/{id}', function ($id) {
    $user = User::find($id);
    return view('user.profile', ['user' => $user]);
});
AThe view file 'user.profile' does not exist
BThe User model is not imported or defined
CThe route URL is missing a trailing slash
DThe route method should be post, not get
Attempts:
2 left
💡 Hint
Check if all classes used are properly imported.
🧠 Conceptual
expert
1:30remaining
What happens when you run this Artisan command?
You run php artisan make:controller ProductController --resource. What does this command do?
ACreates a controller with methods for all RESTful actions
BCreates a controller with only an index method
CCreates a model named ProductController
DDeletes the existing ProductController if it exists
Attempts:
2 left
💡 Hint
Think about what the --resource flag means in Laravel controllers.