Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional statement in FormRequest

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.

like image 599
jemz Avatar asked Jul 30 '26 14:07

jemz


1 Answers

You can use $this->input('department') inside your form request methods since FormRequest extends the Request class.

like image 126
Hockic Avatar answered Aug 01 '26 03:08

Hockic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!