Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kickthemooon's avatar

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?

0 likes
4 replies
RachidLaasri's avatar

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);
}
kickthemooon's avatar

@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?

RachidLaasri's avatar

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]);
}
2 likes
yansusanto's avatar

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 or to participate in this conversation.