我在尝试在身份验证事件后获取用户模型时收到此错误
local.ERROR:类型错误:参数1传递给 App \ Listeners \ LogAuthenticated :: handle()必须是。的实例 照亮\支持\外墙\验证
这是我的监听器文件的样子:
<?php
namespace App\Listeners;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Carbon;
use User;
use Auth;
class LogAuthenticated
{
public function __construct()
{
//
}
public function handle($event)
{
$user = Auth::user();
$userId = $user->user_id;
echo $userId;
}
}
当用户登录时,侦听器事件会很好地执行,但是当我尝试查找用户的ID时,它会出错。我无法弄清楚为什么。
The documentation on handle() method in listeners doesn't mention how to handle Auth
有人可以帮忙吗?
答案 0 :(得分:0)
<?php
namespace App\Listeners;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use User;
use Auth;
use Illuminate\Auth\Events\Authenticated;
class LogAuthenticated {
public function __construct() { }
public function handle(Authenticated $event) {
$user = $event->user;
echo $user->id;
}
}