检查 laravel 中是否没有消息
Check if I have no messages in laravel
我使用这个包: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();
在收件箱中我有一个已清除的对话,但我需要隐藏已清除的对话。
当您调用 get() 时,$conversations return 是一个集合吗?如果是这样,那么您是否可以不使用 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
}
我使用这个包: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();
在收件箱中我有一个已清除的对话,但我需要隐藏已清除的对话。
当您调用 get() 时,$conversations return 是一个集合吗?如果是这样,那么您是否可以不使用 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
}