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 insert dynamic value to additional column in pivot table in laravel
- Input file with max size validation in laravel
- How to update record after save method in Laravel
- Laravel 10 starter app using breeze on live server
- Delete file from amazon s3 bucket using Laravel
- How to check email is valid or not in Laravel
- Wheredate in laravel not working
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Permanently delete a record in laravel
- How to send email in laravel
- How to add script on specific view file in laravel while extending layout
- Save or update pivot table data with additional column in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Get products with number of orders in Laravel
- Pass variable from blade to controller Laravel
- The openssl extension is required for SSL/TLS protection but is not available
- How to create pivot table in laravel using migration
- How to check record exist or not in relationship table
- How to display a specific word from a string in laravel
- Comment .env file in laravel
- Datetime field in Laravel migration
- Extra Filter Query on Relationships in Laravel
- How to get only time from created_at in laravel
- How to customize pagination view in laravel