如何将FormRequest应用于API JSON请求?

时间:2018-11-21 21:16:39

标签: laravel laravel-5

如何对API JSON请求采用FormRequest?现在看起来像:

class CreateOrder extends FormRequest
{

 // Validation rules

   public function rules()
{
    return [
        'DeliveryDate' => 'required|date_format:d-m-Y H:m:s',
        'PostCard' => 'boolean',
        'PostCardText' => 'string|max:250',
        'PhotoBefore' => 'boolean',
        'Remark' => 'string|max:200',
        'OrderDate' => 'required|date_format:d-m-Y',
        'CallRecipientBefore' => 'boolean',
        'AnonymousDelivery' => 'boolean',
        'PhotoAfter' => 'boolean',
        'Employers_Id' => 'required|integer',
        'Employers_Id' => 'required|integer',
        'Partners_Id' => 'required|integer',
    ];
}

   public function authorize()
   {
       return true;
   }

}

并使用:

public function store(CreateOrder $request)
{

 dd(Request::get('DeliveryDate'));
 dd($request->all()); // Or
}

当我向该端点发送数据时,Laravel会显示重定向的数据,而不是显示传入数据$request

发送数据 使用Postman数据以原始格式发送:

{
"DeliveryDate": "2018-01-01"
}

结果,我给了Laravel屏幕保护程序。

所以,我做了一些测试,根本没有调用method:

 public function store(CreateOrder $request)
    {

        dd('ss');
    }

似乎是一个错误:CreateOrder

0 个答案:

没有答案