1

I have tried to access Auth::user() object in group function in Web.php file but it return null value. PLease look my code of web.php file.

 Auth::routes();  
    Route::group(['domain' => 'local.proaisys.com','middleware' => ['auth']], function(){
        //dd(\Auth::check());
        dd(Auth::user());
        Route::get('/dashboard','DashboardController@crm');

    });

enter image description here

7
  • what's the result of Auth::check()? Commented Aug 24, 2017 at 1:08
  • @Wreigh it show false result. Commented Aug 24, 2017 at 7:49
  • I think anything about Auth is not yet processed at that point? Commented Aug 24, 2017 at 7:55
  • If user is null, and check says false, there is no user logged in, right? What is the problem? :-) Commented Aug 24, 2017 at 8:18
  • @Don'tPanic User is logged in but not able fetch user details using Auth::user(). Commented Aug 24, 2017 at 8:20

3 Answers 3

2

What you are trying to achieve here!!

This is you routes/web.php file. You need to pass your query inside function, not outside that. How will route know that you need user inside route!!

Try this:

Route::group(['domain' => 'local.proaisys.com','middleware' => ['auth']], function(){
    //dd(\Auth::check());

    Route::get('/dashboard',function() {
        dd(Auth::user());
//Now goto your domain.com/dashboard  your will get user
    });

});

Or you can get dd(Auth::user()) in your function DashboardController@crm You need to give some route in which you want, but you are trying to access it from outside of function.

Hope it helps...Enjoy

Sign up to request clarification or add additional context in comments.

Comments

0

Try to login your account. Then try to check again. if Auth::user() returns null again. try to check this link https://laracasts.com/discuss/channels/laravel/authuser-returns-null-in-laravel-52

Comments

0

If you have primary key in your users table, named other than id then it may cause this problem.

The primary key in users table should be named as id (case-sensitive).

2 Comments

As It is id only primary key in DB
Its difficult to understand with the information posted. Can you post more code/explanation, i.e. Users model class, your table structure, login code etc ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.