我在函数中从数据库发出请求,但随后收到错误trying to get property of non-object
。但我的代码没有任何问题,它返回错误
>>trying to get property of non-object.
控制器
public function shopHook(Request $request)
{
$shop = $request->getContent();
$shop = json_decode($shop, true);
$shop_id = $shop['number'];
$get_msg = ShopCancelled::where('name',Auth::user()->domain)->first();
}
Web路由
Route::post('shop-cancel-webhook', 'AppController@shopHook');
为什么会发生这种情况?的代码似乎坏了
$get_msg = ShopCancelled::where('name',Auth::user()->domain)->first();
提出请求时
我认为问题出在这一行:
$shop_id = $shop['number'];
尝试$shop_id = $shop->number;
该错误是因为您试图访问未实例化或没有该属性的对象内部的属性。如果你能准确地指出出现错误的那一行,那将很有帮助。