I am making a request from my database in function but then I get an error trying to get property of non-object. But nothing is wrong with my code for it to return the error
>>trying to get property of non-object.
Controller
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
Route::post('shop-cancel-webhook', 'AppController@shopHook');
Why could this be happening? The code seems to be breaking at
$get_msg = ShopCancelled::where('name',Auth::user()->domain)->first();
When making the request
Auth::user()is null. Is the authentication working properly?domain:Auth::user()->domain