首页 > 解决方案 > 如何从请求 Laravel 中获取 JSON?

问题描述

我使用这种方法:

public function store(CreateEvent $request)
{
    dd($request->json()->all());

}

我的要求是:

{"name":"etegjgjghjghj","date":"2019-03-08"}

标题:

Accept: application/json, text/plain, */*
Content-Type: application/json
Origin: http://localhost:4200

作为响应,我在 Chrome 网络中得到空白页面,没有响应数据。

我试过这个:

public function store(CreateEvent $request){ dd('test'); }

标签: laravellaravel-5

解决方案


尝试这个:

public function store(CreateEvent $request)
{
    return response()->json($request->all());
}

推荐阅读