What is the best way to query a user's data in Laravel?

1

When displaying multiple data from a user in a view, is it best to do it in a way?

Option 1 (pass data to the view):

$usuario = Auth::user();
return view('painel.usuarios.perfil', compact('usuario'));

Option 2 (directly in the view):

Auth::user()->name
Auth::user()->email

When I say the best option, I'm considering good practices and especially performance issues. Consider the Laravel 5.3 framework

    
asked by anonymous 07.11.2016 / 18:04

1 answer

2

This is a matter of opinion and need, but I usually like to return by the controller, so as not to leave very large attribute calls in the view:

$usuario = Auth::user();
return view('painel.usuarios.perfil', compact('usuario'));

And the data that is in another table but inside the user ( in this example ), I manipulate in the view, not to return many variables:

$usuario->cpf->numero;
    
07.11.2016 / 18:11