I use form request to validate data from forms($request->url attribute).However in one of my middleware for another route , i want to execute validation again.If i set a value for $request->url , how can i call the form request again.I want to eliminate code duplication here as the form request already contain the form validation that i need
Place all your validation into a FormRequest class, and then for each route you require it, just typehint it within the corresponding controller's method. The validation will automatically be ran.
public method store(\App\Http\Requests\MyRequest $request)
{
// This code will not execute if validation fails
}
@martinbean While I agree with you, the response is not constructive.
Correct me if I'm wrong; FormRequest should be used when validating input data ( Whether it's user input or otherwise ) and Middleware for other things such as headers or other validation logic that touch more than a single type of resource. ( IE: Covering an entire route group for an external API call with a JWT token third-party scope validation )