user13815476
user13815476

Reputation:

Auth::user()->name is not working in package view in laravel?

I have developed a package for Laravel in which I'm trying to fetch the logged in user name but it is giving error. package is currently in the vendor folder

error

ErrorException (E_ERROR)
Trying to get property 'name' of non-object

How I can get current logged in user name?

Upvotes: 3

Views: 1107

Answers (2)

Mudit Gulgulia
Mudit Gulgulia

Reputation: 1266

You can use

{{auth()->user()->name}}

instead of what you are using currently.

Upvotes: 0

Tirdad Abbasi
Tirdad Abbasi

Reputation: 737

Please try to add web middleware in your route like this

Route::group(['middleware' => ['web']], function () {

    Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
        Route::get('/', ['uses'=>'Admin@index']);
    });
});

Upvotes: 3

Related Questions