mardi 5 avril 2016

How to Get the logged in User ID in Laravel 5.2

In my application I used the scaffolding method for creating authentication fast. But I just got one problem while playing with it. Actually I can get Auth::user()->name current logged in user username and other details but I can't get the user ID , I tried to get the ID with Auth::user()->id and Auth::id() but all in vain. Is there any method to get the current logged in user ID ?

What I tried :

I created a variable in AuthServiceProvider and then tried to get the ID in view like this

ServiceProvider

$id = Auth::id();
view()->share('id', $id);

View

>  <li><a href="{{ url('/users/{!! $id !!}') }}"><i class="fa fa-btn
> fa-sign-out"></i>Profile</a></li>

Next Try in View:

<li><a href="{{ url('/users/{!!Auth::user()->id!!}') }}"><i class="fa fa-btn fa-sign-out"></i>Profile</a></li>

I want to get the logged in user ID so that I can show every user his/her profile.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire