6

This is the default laravel notifications data field

{
  "type":"Update Appointment",
  "appointment_id":"379",
  "date":null,
  "updated_by":"Mahir",
  "status":"2"
}

In controller i want to get all notifications with status = 2 and mark as read

Laravel 5.3 doc shows

$user = App\User::find(1);

foreach ($user->unreadNotifications as $notification) {
    $notification->markAsRead();
}

How do i modify this to get all notifications with status = 2

Update : looking for something like this

$noti = $user->unreadNotifications->where('data->status',"2");

Note : my database doesn't support json data type.

1
  • seriously, know one answered :( Commented Aug 30, 2017 at 8:25

3 Answers 3

5

According to laravel 5.6: JSON Where Clauses

and work with MySQL 5.7

I hope this answer help you

Sign up to request clarification or add additional context in comments.

Comments

2
$user = $user->unreadNotifications->where('data.complaint_id',1);

Its work fine for me, I hope it's helpful for you.

Comments

1

I think, you can create your own channel, (see also Illuminate\Notifications\Channels\DatabaseChannel), where you can override send() method, for saving your notifications. Before that, you can write your migration to update "notifications" table to add your custom filtering field. See: https://laravel.com/docs/5.5/notifications#custom-channels

Sorry for my English. Hope, you'll understand.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.