用户加入频道时是否有时间获取时间?

问题描述 投票:1回答:1

我正在开发用户加入频道的应用。当用户订阅频道时,我需要抽时间。有办法实现吗?

Broadcast::channel('chat', function ($user) {
        $ip = Request::ip();
        if (auth()->check()) { 
            return [
                'id' => $user->id,
                'ip' => $ip,
                'name' => $user->name
            ];
        }
    });
laravel
1个回答
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();
© www.soinside.com 2019 - 2024. All rights reserved.