Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Php Can';无法从laravel上的请求中获取属性_Php_Laravel_Request - Fatal编程技术网

Php Can';无法从laravel上的请求中获取属性

Php Can';无法从laravel上的请求中获取属性,php,laravel,request,Php,Laravel,Request,当控制器尝试获得如下请求时,它将工作 $test = $request->base; return response()->json(['test' => $test]); 前端将获得如下json: {name: "aaaa", price: null, discounted: null, area: null, address: null, …} 但当我尝试获取“name”属性时: $test = $request->base $test2 = $test->

当控制器尝试获得如下请求时,它将工作

$test = $request->base;
return response()->json(['test' => $test]);
前端将获得如下json:

{name: "aaaa", price: null, discounted: null, area: null, address: null, …}
但当我尝试获取“name”属性时:

$test = $request->base
$test2 = $test->name;
return response()->json(['test' => $test2]);
然后我在网络预览时出错:

{message: "Trying to get property of non-object", exception: "ErrorException",…}
原因是$request->base不再得到任何东西

$test = $request->base
$check = gettype($test);  // shows null
$test2 = $test->name;
return response()->json(['test' => $test2]);
为什么会发生这种情况?如何获得这样的属性:

$request->base->name

尝试此数组,对象的类型不同。在第一行中,我们在$test中有一个数组,所以您将无法使用->操作符访问其中的内容

$test = $request->base
$test2 = $test['name'];

$request->base
的值是多少?你确定这是个物体吗?
$test['name']
有效吗?$request->base是一个类似于以下内容的json:{name:“aaaa”,price:null,折扣:null,area:null,address:null,…}当我将$test2=$test->name更改为$test2=$test['name']时,它有效;但是$test2=$test->name和$test2=$test['name']之间有什么不同呢?为什么$test2=$test->name不能工作?如果
$test['name']
可以工作,
$test
是一个数组,而不是一个对象。在这两种数据类型中访问参数的方式不同。似乎我对数据类型感到困惑。谢谢你的帮助,兄弟!谢谢,我意识到请求的属性不是json。这就是工作。