After Laravel 5.5, you can create your own custom validation rule parameter.
To create a new rule, simply run the artisan command:
php artisan make:rule GreaterThanTen
laravel will place the new rule class in the app/Rules
directory
An example custom object validation rule might look something like this:
namespace App\Rules; use Illuminate\Contracts\Validation\Rule; class GreaterThanTen implements Rule {
With a specific user rule, you can use it in your controller check as follows:
public function store(Request $request) { $request->validate([ 'age' => ['required', new GreaterThanTen], ]); }
This method is much better than the old way to create Closures
in the AppServiceProvider
class.
source share