Mohammad Naji
Mohammad Naji

Reputation: 5442

Check if a route parameter exists in Laravel custom validation rule?

Consider the following URIs:

I do already have a rule check_country_contains_person working fine, but I should extend it to check_group_contains_person to be used in both method's validation classes.


Inside Validation Rule's passes function, how can I check if request()->route('country') and/or request()->route('city') are available or not?

Please note that if I were sure which one exists, I could do the rest. That's just about checking availability of the route parameters.

Upvotes: 2

Views: 4156

Answers (1)

Amirh
Amirh

Reputation: 473

To check existence of a route parameter in laravel just check this:

is_null($request->route('sample'))

Upvotes: 2

Related Questions