Error: Undefined variable: user
How can I fix this beautifully? I can assign $user to assign some default value, but it probably will not be nice. Maybe there are some other options?

enter image description here

  • so the error is lower when I pass a non-variable to the view. - Andrii
  • one
    Emae, it will be more beautiful in if to do } else { $user = array(); } } else { $user = array(); } - Manitikyl
  • one
    in fact, in this case, assigning $user starting value will not be a bad option. - Manitikyl
  • @entithat -.- because the logic will be broken. - Manitikyl
  • @entithat I noticed, I would not have written. if you add a return to if , then if Auth::check gives TRUE , then everything is fine. BUT if it gives FALSE , then your function will not return anything, because return in if , and duplicating 2 times the return view... is bad, because duplicate code. - Manitikyl

1 answer 1

Before if, put at least $ user = null, because if the user is not authorized, you will not have it declared