Last active
November 28, 2017 06:36
-
-
Save cyberfly/eafdd4096ab583223c2d to your computer and use it in GitHub Desktop.
Different method to fetch current login user info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| 1. Use method injection | |
| */ | |
| //use the namespace | |
| use Illuminate\Contracts\Auth\Guard; | |
| public function confirm(Guard $auth) | |
| { | |
| $name = $auth->user()->name; | |
| $email = $auth->user()->email; | |
| } | |
| /* | |
| 2. Use Facade | |
| */ | |
| public function confirm() | |
| { | |
| $name = \Auth::user()->name; | |
| $email = \Auth::user()->email; | |
| } | |
| /* | |
| 3. Import the namespace at the controller top | |
| */ | |
| use Illuminate\Support\Facades\Auth; | |
| //alternatively can use this syntax for simpler, check at config/app.php alias | |
| use Auth; | |
| public function confirm() | |
| { | |
| $name = Auth::user()->name; | |
| $email = Auth::user()->email; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment