vendredi 28 avril 2017

Laravel: what's the better method to retrieve current logged user and why?

I know two method:

The first is using a Request object param in the controller's function

public function index(Request $request)
{   
    $user = $request->user();
    return view('home');
}

The second is using directly the Auth facade.

public function index()
{   
    $user = Auth::user(); 
    return view('home');
}

Are there any diferences? Are one method better that the other one and, if, yes, why?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2pcds7Z
via IFTTT

Aucun commentaire:

Enregistrer un commentaire