Description
A set of useful Laravel validation rules
Available rules
- Authorized
- CountryCode
- Currency
- Enum
- ModelsExist
- Delimited
Authorized
Determine if the user is authorized to perform an ability on an instance of the given model. The id of the model is the field under validation
Consider the following policy:
class ModelPolicy{ use HandlesAuthorization; public function edit(User $user, Model $model): bool { return $model->user->id === $user->id; }}
This validation rule will pass if the id of the logged in user matches the user_id on TestModel who's it is in the model_id key of the request.
// in a `FormRequest` use Spatie\ValidationRules\Rules\Authorized; public function rules(){ return [ 'model_id' => [new Authorized('edit', TestModel::class)], ];}
Optionally, you can provide an authentication guard as the third parameter.
new Authorized('edit', TestModel::class, 'guard-name')
Recent Courses on Laravel Daily
AI Agents/IDEs for Laravel: May 2026 (Claude Code, Codex, OpenCode, etc)
7 lessons
52 min
Roles and Permissions in Laravel 13
14 lessons
57 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read