I have a page where each user has their profile that they can browse and see their created pages called "builds". I have this user, userA, without any builds that is getting the following exception as soon as you go to his profile:
ErrorException (E_ERROR)
Undefined variable: build (View: /var/www/html/example/resources/views/profiles/show.blade.php)
Previous exceptions
Undefined variable: build (0)
When I look him up using tinker the user doesn't have any builds:
>>> $user = App\User::where('username', 'userA')->first();
=> App\User {#3073
id: 731,
username: "userA",
email: "email@example.com",
email_verified_at: "2019-11-15 16:22:03",
created_at: "2019-11-10 18:31:54",
updated_at: "2019-11-15 16:22:03",
}
>>> $user->builds;
=> Illuminate\Database\Eloquent\Collection {#3078
all: [],
}
>>>
I have another user, userB, also without any builds that is working just fine when you go to his profile, no exception is shown. This is the data that tinke returns for userB:
>>> $user = App\User::where('username', 'userB')->first();
=> App\User {#3066
id: 1,
username: "userB",
email: "email@example.com",
email_verified_at: "2019-10-08 20:51:32",
created_at: "2019-10-03 00:44:02",
updated_at: "2019-10-08 20:51:32",
}
>>> $user->builds;
=> Illuminate\Database\Eloquent\Collection {#3061
all: [],
}
>>>
So I have 2 users, without any builds. You can view the profile of userB but userA throws an exception for some reason. In my view I made sure to check if there are any builds for the user by using:
@if($builds->isEmpty())
User has not created any builds.
@else
@foreach...
I have not experienced this for weeks when a user all of a sudden reported to me today that they are not able to view their profile. Does someone know what is causing this?