0

I am trying to get a logged in user data like id, name, email etc. I have to compare this id with another table called adminpictures and then display this picture if any record found against this id.

here is my code for getting user id

$id = Auth::id();
        dd($id);

but it return null, i want logged in user id. How i can do that. I am new in laravel

Muhammad Arslan
  • 442
  • 1
  • 9
  • 25

3 Answers3

1

you can use sentinel middleware for this.write this code in your controller if you are using default User model as your model for table in database.this code will work

use Sentinel;
$user = Sentinel::getUser();
dd($user);

this will print the user logged in refer more on sentinel here https://cartalyst.com/manual/sentinel/2.0

Al Ameen
  • 312
  • 3
  • 9
0

Try this:

$id = Auth::user()->id;
        dd($id);
Gulmuhammad Akbari
  • 1,986
  • 2
  • 13
  • 28
0

You've a typo within your code, it should be

$id = Auth::user()->id;

and not

$id = Auth::id();

You can check user is logged in or not simply using

if (Auth::check())
{
    // The user is logged in...
    $id = Auth::user()->id;
}
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54