Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel all input fields are required

I have about 50 input fields and they are all required. Is there a easy way to check if they are all set? So i don't have to manually put every field in my model with a validation rule of "required"?

like image 744
Eric Geurts Avatar asked Oct 15 '25 17:10

Eric Geurts


2 Answers

I know this is late, but I wrote a simple function to solve this problem for myself

foreach ($request->except('_token') as $data => $value) {
  $valids[$data] = "required";
}

$request->validate($valids);

Good luck!

like image 131
Okiemute Omuta Avatar answered Oct 18 '25 13:10

Okiemute Omuta


You can use the code below. This worked for me to make all request fields required.

$request->validate([
        '*' => 'required',
    ]);
like image 28
Nadir Musayev Avatar answered Oct 18 '25 11:10

Nadir Musayev



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!