检查我是否在laravel中没有消息

时间:2018-03-11 12:18:25

标签: php laravel chat

我使用这个包:https://github.com/musonza/chat
我有一个函数inbox

public function inbox(Request $request) {
    $user = $this->user;
    //$conversations = Chat::commonConversations($user);
    //$LastMessages['partcipant'] = $conf->users[1];
    $conversations = Chat::conversations()->for($user)->limit(15)->page($request->page)->get();
    //dd($conversations); exit;
    //dd($conversations);
    $recipient = [];
    //dd($conversations);
    foreach($conversations as $conf) {
        $recipient[] = $conf->users()->where('user_id', '<>', $user->id)->first();
    }

    //dd($recipient);

    return view('inbox.index', compact('conversations', 'recipient'));
}

我如何检查,如果在谈话中我没有消息?如果是这样,请在收件箱中隐藏对话。现在我有:

$conversations = Chat::conversations()->for($user)->limit(15)->page($request->page)->get();

当我清除对话时:

Chat::conversations($conversation)->for($user)->clear();

在收件箱中,我已清除对话,但我需要隐藏清除对话。

1 个答案:

答案 0 :(得分:0)

当您调用get()时,$ conversations会返回一个集合吗?如果是,那么您是否可以不使用isEmpty()函数来检查$ conversations是否是用户没有消息?

例如,您可以尝试:

$conversations = Chat::conversations()->for($user)->limit(15)->page($request->page)->get();

if ($conversations->isEmpty()) {
// this is an empty conversation and thus user has no messages
}