DEV Community

Cover image for Different ways to use Laravel Form Requests

Different ways to use Laravel Form Requests

Othmane Nemli on June 29, 2021

Laravel provides several different approaches to validate your application’s incoming data. It is most common to use the validate method available ...
Collapse
 
ayoubbousetta profile image
AYOUB BOUSETTA

Not bad, but i guess it's a little bit over-engineered

Collapse
 
muhammadmp profile image
Muhammad MP

I prefer to create another form request class for the update method.

Collapse
 
bowie profile image
Bowie

+1 to this. I've created two classes both extending the FormRequest class for this. Alternatively you could create a super class in between for inheritance. While the proposed method in this article isn't bad, I prefer this method personally

Collapse
 
othmane_nemli profile image
Othmane Nemli

It just depend on how you want to structure your project.

Collapse
 
jovialcore profile image
Chidiebere Chukwudi

This!...

Collapse
 
franciscocaldeira profile image
Francisco

what about authorize()? for the store(), update(), destroy(), view() ?

Collapse
 
rf14 profile image
Arif Zuhairi

Thank you Othmane, this is really good writeup for me to understand, maybe just some little typos in 1st & 3rd pictures, I think

Collapse
 
othmane_nemli profile image
Othmane Nemli • Edited

It's my pleasure that was helpful for you.. and thank you for pointing the typos :)

(y)

Collapse
 
sahandi81 profile image
Sahand RahmatPanah

ok, thats good. i want to call $controller->store() manually. how can i create request for store method ???

Collapse
 
camohub profile image
camo

Why this does not work inside form request?
$this->input('notification_type_id', null) // Always returns null

Collapse
 
shraddha2v9kulkarni profile image
shraddha2v9kulkarni

Thanks to share this idea. It's different approach to learn.

Collapse
 
mubarak profile image
Ahmed Mubarak

Such a great article, but I was wondering how to pass data like route parameters into the form request, I tried many techniques as per Laravel docs but unluckily did not work for the form request.