Is it appropriate to display all user information using auth::guard laravel authentication?
P粉256487077
2023-09-04 17:46:44
<p>I am new to Laravel. I have a question in my mind... is it correct to use auth::guard to display all user information. Am I using Laravel Breeze authentication? </p>
<p>For example. Is that so-</p>
<pre class="brush:php;toolbar:false;">name: Auth::guard('web')->user()->name
mobile: Auth::guard('web')->user()->mobile
address: Auth::guard('web')->user()->address
city: Auth::guard('web')->user()->city
gender: Auth::guard('web')->user()->gender</pre>
<p>Like this? </p>
This can work, but it's more common to write it like this. If you're sure your user is logged in, you can skip any extra checks for $user.
If your user may not be logged in, you can add a row-specific check like this:
If your users may not be logged in and you want to make sure they are always logged in, you can do the following: