Complete the code to protect a route with authentication middleware in Laravel.
Route::get('/dashboard', function () { return view('dashboard'); })->middleware('[1]');
The auth middleware ensures only authenticated users can access the route.
Complete the code to hash a password before saving it in Laravel.
$user->password = [1]($request->password);Laravel uses bcrypt to securely hash passwords before storing them.
Fix the error in the CSRF token field in a Blade form.
<form method="POST" action="/submit"> [1] <input type="text" name="name"> <button type="submit">Submit</button> </form>
In Blade templates, @csrf is the directive to include the CSRF token field.
Fill both blanks to validate input and prevent SQL injection in Laravel.
public function store(Request $request) {
$validated = $request->validate([[1] => 'required|string|max:255']);
User::create([[2] => $validated['name']]);
}Both blanks use the key 'name' to validate and save the user's name safely.
Fill the blanks to safely retrieve user input, validate it, and hash the password.
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'])
]);
}The code safely gets 'name' and 'password', validates them, and hashes the password before saving.
