Answer the question
In order to leave comments, you need to log in
Why is undefined index happening?
If I output like this, then an undefined index error occurs when outputting to the view:
public function getUser()
{
$user = User::where('id','3')->get();
return view('layouts/panel', compact('user'));
}
public function getUser()
{
$user = User::find(3);
return view('layouts/panel', compact('user'));
}
Answer the question
In order to leave comments, you need to log in
In the first case, you have a collection (albeit from one element), and in the second, you have a model right away.
Most likely, you are trying to access some user attribute, but you are trying to get it on the collection - that's the error.
You didn't provide a view code or an index name, so there's nothing more to say.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question