read messages and not yet read I have inquiries in my app that visitor and customer can send for an offer.
Now I want to mark new inquiries as unread and when the admin opens the inquiry in the admin area I want to change it to read. so I want to be able to filter inquiries based on that.
Ideas?
First of all, you add a column to your messages table named status for example.
When you first send a message the status is gonna be 1 ( unread ) when an admin/user opens the message the status gets updates to **0** ( read )
You can use QueryScopes for that :
public function scopeUnread($query)
{
return $query->where('status', 1);
}
public function scopeRead($query)
{
return $query->where('status', 0);
}
@RachidLaasri "when an admin/user opens the message the status gets updates to **0** ( read )"
How do I update the status when the user opens the message the first time?
You don't have to check if it's the first time or no, you can simply do :
$message->update(['status' => 0]);
Or you can check if it's already equal to 0 and just continue without sending another SQL update request :
if($message->status == 1) {
$message->update(['status' => 0]);
}
When you first send a message the status is gonna be 1 ( unread ) when an admin/user opens the message the status gets updates to **0** ( read )
I'd like to know what trigger the status change/update. A page load, a link clicked, or...??
This is the part that I'm still confused.
PS: Sorry for bumping an old thread as I found nothing googling :P
Please sign in or create an account to participate in this conversation.