doudi8519 2017-02-03 16:43 采纳率: 100%
浏览 607
已采纳

Laravel 5.4 Multi auth - Auth :: guard() - > user()为空

I've created a multi auth test in Laravel 5.4. It's using custom middlewares, custom Eloquent providers, etc. The auth flow is working, I can login in both ways. But if the user is signed in, in the home controller when I want to check the user with Auth::user() or Auth::guard()->user(), it's empty. The Auth::guard() is empty as well. But I don't understand, why?! It should contains the signed in user instance, shouldn't it?

Also the $request->getUserResolver() says that the guard is null... o.O

What did I do wrong?

Here it is my test repo, if you want to check my code.

Thank you in advance!

Edit 1:

In the \app\Http\Controllers\Employee\HomeController.php the Auth::guard()->user() and the Auth::user() are empty.

namespace App\Http\Controllers\Employee;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller
{

    public function __construct(Request $request)
    {
        $this->middleware('auth.employee:employee');
    }

    public function index(Request $request)
    {
        $users[] = Auth::user();
        $users[] = Auth::guard()->user();
        $users[] = Auth::guard('employee')->user();

        dd($users);

        return view('employees.home.index');
    }
}
  • 写回答

2条回答 默认 最新

  • dongyihao1099 2017-04-02 08:53
    关注

    Auth::shouldUse(your_guard_name);
    call this in your login function

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿