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
- Remove public from url in laravel project
- Get last year created records in Laravel
- How to authenticate admin users in Laravel ?
- How to add a key value pair to existing array in laravel
- How to call Laravel route in jQuery
- If condition in foreach loop in laravel
- Laravel route redirect not working
- How to randomly get the user id from users table in laravel
- The use statement with non-compound name 'DB' has no effect
- Conditional where clause in Laravel
- Extra Filter Query on Relationships in Laravel
- Insert current date time in a column using Laravel
- Update existing pivot table data in laravel
- Insert Comma Separated Values in laravel
- Return redirect laravel not working
- How to get count of all records created at yesterday
- Trying to access array offset on value of type null error in laravel
- How to pass query string with pagination in laravel
- How to get id of next record in laravel
- How to get specific columns using Laravel eloquent methods
- How to call model in blade laravel
- Call to a member function pluck() on array
- Laravel recursive function in controller
- How to use bootstrap pagination in laravel 8
- Use withCount() to Calculate Child Relationship Records