thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.81k stars 2.67k forks source link

Trying to get property 'avatar' of non-object [master.blade.php ] #5096

Open Heqma opened 4 years ago

Heqma commented 4 years ago

Version information

Description

I'm trying to cache files in /admin/compass "php artisan config:cache / php artisan route:cache"

Logs

[2020-09-27 14:12:31] local.ERROR: Trying to get property 'avatar' of non-object (View: /home/servername/domains/mydomain/subdomain/vendor/tcg/voyager/resources/views/master.blade.php) {"exception":"[object] (Facade\Ignition\Exceptions\ViewException(code: 0): Trying to get property 'avatar' of non-object (View: /home/servername/domains/mydomain/subdomain/vendor/tcg/voyager/resources/views/master.blade.php) at /home/servername/domains/mydomain/subdomain/vendor/tcg/voyager/src/../resources/views/master.blade.php:67)

Master.blade.php:67 start from if

 <?php
if (\Illuminate\Support\Str::startsWith(Auth::user()->avatar, 'http://') || \Illuminate\Support\Str::startsWith(Auth::user()->avatar, 'https://')) {
    $user_avatar = Auth::user()->avatar;
} else {
    $user_avatar = Voyager::image(Auth::user()->avatar);
}
?>
MrCrayon commented 3 years ago

Even if it show that error commands are actually working, so even if not ideal is still functional. Not sure what's happening but I suppose those commands are killing the session in some way so that's not possibile to show the result.

JuanGonzalezABI commented 3 years ago

put use TCG\Voyager\Http\Middleware\VoyagerAdminMiddleware;

and

    $this->middleware(VoyagerAdminMiddleware::class);

in the construct

qaisarshabbir commented 2 years ago

Can you explain the construc?

I did not understand, where to put these lines that you mentioned.

juliusestebar commented 2 years ago

Can you explain the construc?

I did not understand, where to put these lines that you mentioned.

better use php artisan optimize:clear i solve mine using this

qaisarshabbir commented 1 year ago

I tried php artisan optimize:clear but not solved.

nerfenoff commented 9 months ago

the error is still relevant. Is there a solution?

Emerica commented 9 months ago

How are you coming to this error? Either you're trying to use the master blade in a place where a user isn't logged in or you don't have user(s) in the database. Auth::user() is returning null or false instead of a User.

nerfenoff commented 9 months ago
  1. add Voyager routes in web.php Route::group(['prefix' => 'admin'], function () { Voyager::routes(); });
  2. in compas try run "php artisan optimize" or "php artisan route:cache"

You can also enter commands directly into the console. Then the error message will be in \storage\logs\

nerfenoff commented 9 months ago

Everything works correctly, but caching works out with an error Auth::user() is returning null

I have not tried to use or redefine master blade. It is only used automatically by Voyager itself