Answer the question
In order to leave comments, you need to log in
Why does "Trying to get property of non-object" error appear in Laravel(s)?
$attendedfestivals = Planner::where('user_id', Auth::user()->id)->where('planned_festivals', 0)->get();
Answer the question
In order to leave comments, you need to log in
if (auth()->check())
{
$attendedfestivals = Planner::where('user_id', auth()->user()->id)->where('planned_festivals', 0)->get();
}
else
{
// Обрабатываем ситуацию, когда пользователь неавторизован.
}
Since this is exactly Trying to get property, and not Call to a member function, it means that only Auth::user()->id is suitable for the role of the problem area. Namely, Auth::user() returns something that is not an object.
And yes, if the user is not authorized, then Auth::user() will return null.
trying to take a property not from an object
, check if you have it setAuth::user()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question