Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

HUGE_DICK_10_INCHES's avatar

When do we use make:request in laravel?

I've searched about this long time and all I see everywhere is basic usage of request() or Request $request...

When i search on laravel documentation pages about php artisan make:request something, I looked up for using ajax and only thing on docs is you make new request and for response you get json.

When I look on other websites for using ajax with laravel they make:requests but why when I can use controller and check is request ajax or not, and then do what is needed to?

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

It's used for form validation, so you don't have to do it in the controller. https://laravel.com/docs/5.6/validation#form-request-validation

It works the same whether it's a regular form or ajax request. If you send the right headers with the ajax request, laravel will automatically return json. You don't need to check...it's automatic. You just need to set a "accept: application/json" header and laravel will see that and return json.

You should also be sending "X-Requested-With: XMLHttpRequest" headers

2 likes

Please or to participate in this conversation.