In my controller I have conditional statement before I validate
if ($request->department == 5) {
$this->validate($request, [
//validation here
];
} else {
$this->validate($request, [
//validation here
];
}
Now I create FormRequest php artisan make:request DepartmentRequest
In method rules() , I don't know how to access the department parameter, I tried:
if($request->department == 1) But threw the Exception: Error - undefined $request variable.
You can use $this->input('department') inside your form request methods since FormRequest extends the Request class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With