我正在开发用户加入频道的应用。当用户订阅频道时,我需要抽时间。有办法实现吗?
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
if (auth()->check()) {
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name
];
}
});
为什么不以相同的方式获得$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();