Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a form request class using the artisan command.
Laravel
php artisan make:[1] StoreUserRequest Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'make:controller' instead of 'make:request'.
Using 'make:model' or 'make:migration' which create different classes.
✗ Incorrect
The artisan command to create a form request class is 'make:request'.
2fill in blank
mediumComplete the method name to define validation rules in a form request class.
Laravel
public function [1](): array { return [ 'name' => 'required|string|max:255', 'email' => 'required|email|unique:users,email', ]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'authorize' instead of 'rules'.
Using 'validate' which is not a method in form request classes.
✗ Incorrect
The 'rules' method defines the validation rules in a form request class.
3fill in blank
hardFix the error in the authorize method to allow all users to make the request.
Laravel
public function authorize(): bool
{
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'false' which denies all requests.
Returning 'null' or '1' which are not boolean true.
✗ Incorrect
Returning 'true' in the authorize method allows all users to make the request.
4fill in blank
hardFill both blanks to customize the error message for the 'email' field in a form request class.
Laravel
public function [1](): array { return [ 'email.[2]' => 'Please provide a valid email address.', ]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rules' instead of 'messages' method.
Using 'unique' instead of 'required' for the error message key.
✗ Incorrect
The 'messages' method customizes error messages, and 'required' is the validation rule key for the email field.
5fill in blank
hardFill all three blanks to create a form request class that authorizes all users, defines rules, and custom messages.
Laravel
class StoreProductRequest extends FormRequest { public function [1](): bool { return [2]; } public function [3](): array { return [ 'name' => 'required|string', 'price' => 'required|numeric|min:0', ]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'rules' and 'authorize' method names.
Returning false in 'authorize' method.
✗ Incorrect
The 'authorize' method returns true to allow all users, and the 'rules' method defines validation rules.