Recall & Review
beginner
What is a custom validation rule in Laravel?
A custom validation rule in Laravel is a user-defined rule that lets you check data in ways not covered by Laravel's built-in validators. It helps you create specific checks for your app's needs.
Click to reveal answer
beginner
How do you create a custom validation rule class in Laravel?Use the Artisan command: <code>php artisan make:rule RuleName</code>. This creates a class where you define the <code>passes()</code> method to check the value and <code>message()</code> to return an error message.Click to reveal answer
beginner
What does the
passes() method do in a Laravel custom rule?The
passes() method checks if the given value meets your custom condition. It returns true if valid, or false if invalid.Click to reveal answer
intermediate
How do you apply a custom validation rule to a form request in Laravel?
In your form request's <code>rules()</code> method, add the custom rule class instance to the field's rules array, like <code>'field' => ['required', new RuleName()]</code>.Click to reveal answer
intermediate
Can custom validation rules accept parameters? How?
Yes. You can pass parameters via the rule class constructor when creating the rule instance. Then use those parameters inside <code>passes()</code> to customize validation.Click to reveal answer
Which Artisan command creates a custom validation rule class?
✗ Incorrect
The correct command is
php artisan make:rule RuleName to create a custom validation rule class.What should the
passes() method return if the value is valid?✗ Incorrect
The
passes() method returns true if the value passes validation.Where do you add a custom validation rule in Laravel?
✗ Incorrect
Custom validation rules are added inside the form request's
rules() method.How do you pass parameters to a custom validation rule?
✗ Incorrect
Parameters are passed to custom rules through the constructor when creating the rule instance.
What does the
message() method in a custom rule do?✗ Incorrect
The
message() method returns the error message shown if validation fails.Explain how to create and use a custom validation rule in Laravel.
Think about the steps from creating the rule to applying it in validation.
You got /4 concepts.
Describe how you can customize a Laravel validation rule with parameters.
Focus on how data flows into the rule class.
You got /3 concepts.