How to force FormRequest return json in Laravel 5.1?

前端 未结 5 1637
梦如初夏
梦如初夏 2020-12-05 02:25

I\'m using FormRequest to validate from which is sent in an API call from my smartphone app. So, I want FormRequest alway return json when validation fail.

I saw th

5条回答
  •  悲&欢浪女
    2020-12-05 03:13

    It boggles my mind why this is so hard to do in Laravel. In the end, based on your idea to override the Request class, I came up with this.

    app/Http/Requests/ApiRequest.php

    Then, in every controller just pass \App\Http\Requests\ApiRequest

    public function index(ApiRequest $request)

提交回复
热议问题