
Attempt to read property "avatar" on null in Laravel
Created at 08-Mar-2022 ,
By samar
Attempt to read property "avatar" on null in Laravel
Good day, guys. In this post, we’ll look at how to solve the "Attempt to read property "avatar" on null in Laravel" programming puzzle.
Error Attempt to read property "avatar" on null occurs when you to try to display the user avatar and $user->avatar returns null while displaying user information in blade file.-
Display user avatar with condition in Laravel blade
<img src="{{ $user->avatar !== null ? asset($user->avatar) : asset('/') }}" alt=".."/> //Controller Code. $user = User::query()->where('id','=', $id)->first(); return view('user.profile', compact('user'));
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Insert dummy data in users table Laravel
- Print query in laravel
- Get all users except the followings users in overtrue laravel-follow
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Always load the relationship data with eager loading in Laravel
- Call to a member function update() on null
- Method Illuminate\Http\Request::validated does not exist
- Count all and get 10 records after where condition in laravel
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- Laravel migration add foreign key to existing table
- Redirect from www to non www in laravel using htaccess
- Call to undefined method Illuminate\Support\Facades\Request::all()
- Laravel create multiple records in Pivot table
- Import/Use Storage facade in laravel
- How to check find method executed successfully in laravel
- How to delete record in Laravel with ajax
- Get Array of IDs from Eloquent Collection
- How to check records exist in loaded relationship in Laravel blade view
- After image selected get validation error in laravel
- Convert input array to comma-separated string in laravel controller
- How to get records in random order in laravel
- Target class [HomeController] does not exist
- How to display pivot table column value in laravel
- Laravel file size validation not working
- How to customize or Change validation error messages