Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to protect a route with authentication middleware in Laravel.
Laravel
Route::get('/dashboard', function () { return view('dashboard'); })->middleware('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'guest' middleware which allows only unauthenticated users.
Using 'api' middleware which is for API routes, not authentication.
Using 'web' middleware which is a group, not specifically for auth.
✗ Incorrect
The auth middleware ensures only authenticated users can access the route.
2fill in blank
mediumComplete the code to hash a password before saving it in Laravel.
Laravel
$user->password = [1]($request->password); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insecure hash functions like md5 or sha1.
Using 'hash' without specifying algorithm.
Not hashing the password at all.
✗ Incorrect
Laravel uses bcrypt to securely hash passwords before storing them.
3fill in blank
hardFix the error in the CSRF token field in a Blade form.
Laravel
<form method="POST" action="/submit"> [1] <input type="text" name="name"> <button type="submit">Submit</button> </form>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@csrf_token' which is not a valid directive.
Using '{{ csrf_field() }}' inside Blade without echoing properly.
Using '@token' which does not exist.
✗ Incorrect
In Blade templates, @csrf is the directive to include the CSRF token field.
4fill in blank
hardFill both blanks to validate input and prevent SQL injection in Laravel.
Laravel
public function store(Request $request) {
$validated = $request->validate([[1] => 'required|string|max:255']);
User::create([[2] => $validated['name']]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for validation and creation causing errors.
Using keys unrelated to the input field.
✗ Incorrect
Both blanks use the key 'name' to validate and save the user's name safely.
5fill in blank
hardFill the blanks to safely retrieve user input, validate it, and hash the password.
Laravel
public function register(Request $request) {
$data = $request->only([1], [2]);
$validated = $request->validate([
[1] => 'required|string|max:255',
[2] => 'required|string|min:8'
]);
$user = User::create([
[1] => $validated['name'],
[2] => bcrypt($validated['password'])
]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field names causing validation or saving errors.
Not hashing the password before saving.
✗ Incorrect
The code safely gets 'name' and 'password', validates them, and hashes the password before saving.