Extend Request class in Laravel 5

后端 未结 6 1396
猫巷女王i
猫巷女王i 2020-12-08 22:48

I\'m new to Laravel (only experienced Laravel 5, so no legacy hang up here)

I\'d like to know how to extend the core Request class. In addition to how to extend it,

6条回答
  •  攒了一身酷
    2020-12-08 23:17

    I was able to add custom request object using FormRequest in Laravel 5.5 as follows.

    First, just create FormRequest:

    php artisan make:request MyRequest

    Then just make it look like this:

    You can then use MyRequest as drop-in replacement in any function that takes Request as parameter:

    public function get(MyRequest $request)
    {
    }
    

    I do realize that FormRequests are actually meant to be used for a different purpose, but whatever works.

    Documentation on FormRequest: https://laravel.com/docs/5.0/validation#form-request-validation

提交回复
热议问题