我正在开发用户加入频道的应用程序。当用户订阅频道时,我需要抽时间。有办法实现吗?
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
if (auth()->check()) {
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name
];
}
});
答案 0 :(得分:1)
为什么您获得$ip
的方式不一样?
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
if (auth()->check()) {
$time = now(); // Here
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name,
'joined' => $time,
];
}
});
now()辅助函数返回当前时间的Carbon实例
从docs
now
函数在当前时间创建一个新的Illuminate\Support\Carbon
实例:
$now = now();