I am trying to simple error handling whereby if a query doesn't return anything I want to redirect the user to a 404 page, but for now I just echoing a message to see if it triggers, here is my code
public function show($user_id, $username) {
$user = User::where('id', $user_id)->where('name', $username)->get();
if (count($user = 0)) {
echo "REEEEEEE";
}
else
{
$user->load('comments.users', 'posts.users');
return $user;
}
//return view ('users.show', compact('user'));
}
This only echos the message and doesn't load the relationships or return the user if the query returns something, am I doing something wrong?