Skip to content

Instantly share code, notes, and snippets.

@cyberfly
Last active November 28, 2017 06:36
Show Gist options
  • Select an option

  • Save cyberfly/eafdd4096ab583223c2d to your computer and use it in GitHub Desktop.

Select an option

Save cyberfly/eafdd4096ab583223c2d to your computer and use it in GitHub Desktop.
Different method to fetch current login user info
<?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