Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 休息邮递员要求_Laravel_Rest_Post_Controller_Postman - Fatal编程技术网

Laravel 休息邮递员要求

Laravel 休息邮递员要求,laravel,rest,post,controller,postman,Laravel,Rest,Post,Controller,Postman,我有一个REST POST请求,其格式如下: { "data" : { "type" : "studies", "attributes" : { "age": "9999", "name": "XYZ" } } } 我想能够上传一个文件的要求。所以我的请求主体看起来像这个图像 问题是,在我的控制器中,我无法检测到任何东西 if($request->has('data.attributes.name')) $name = $request->inpu

我有一个REST POST请求,其格式如下:

{
"data" : {
  "type" : "studies",
   "attributes" : {
   "age": "9999",
    "name": "XYZ"
  }
 }
}
我想能够上传一个文件的要求。所以我的请求主体看起来像这个图像

问题是,在我的控制器中,我无法检测到任何东西

if($request->has('data.attributes.name'))  $name = $request->input('data.attributes.name')
if($request->has('data.attributes.age'))  $name = $request->input('data.attributes.age')

if($request->hasFile('data.attributes.file')){ 
  //Upload the file 
}

不幸的是,我的控制器无法检测这些属性。我应该如何在邮递员中输入它们?

Dot delimeter将转换为
。因此,您可以:

{
    "data_attributes_file": "file",
    "data_attributes_name": "XYZ",
    "data_attributes_age": "999"
}

如果您仍然有一个空页面或错误
519
问题,则需要将
CSRF
令牌放入Cookie中,或将其删除

app/Http/Middleware/VerifyCsrfToken

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '*',
    ];
}

可以使用数组表示法语法

data[attributes][file]
data[attributes][name]
data[attributes][age]
参见示例

您在《邮递员》中的状态是419还是200?谢谢。这是正确的,但另一个答案也是正确的,但遵循另一个答案意味着我不需要更改控制器代码。谢谢。它也起作用了。第一个答案也是正确的
data[attributes][file]
data[attributes][name]
data[attributes][age]