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
- How to fetch single row data from database in laravel
- How to get single column value in laravel
- Laravel save object to database
- Drop foreign key column in Laravel using migration
- There are no commands defined in the "route:" namespace
- Laravel 7 login error message not showing
- How to disable timestamps in laravel
- Laravel 10 Breeze Authentication Example
- Recursive function example code PHP Laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- How to get last month records in Laravel
- Laravel 5.4 save data to database
- Get the post details if it has at least one comment in comments table
- Trying to get property 'title' of non-object
- Symlink(): No such file or directory
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- How to upload multiple images after preview in laravel using cropper js
- Validation errors for multiple forms on same page Laravel
- On delete set foreign id column value null using migration in laravel 8
- How to get the random value form a specific column in laravel ?
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to make Copy or Duplicate table row in laravel
- How to get tomorrow and yesterday date in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists