Select Laravel Notification.

Prettify Studio
Nov 2 · 1 min read

3aslema(Hi in Tunisian Language)

Often in your Laravel project, you may want to select notifications based on some values in the ‘data’ field in order to delete them or update them. Let’s say an ID, or something else.

Using the normal where clause will do nothing, because we have JSON field.

So we are going to use JSON inline path operator.

Given the schema of the notification table:

id | type | notifiable_id | notifiable_type | data | read_at | created_at | updated_at

We have data field as follows

{“username”:”user”,”post_id”:1}

So we want to select the notification where the post id is 1:

So here’s the code

Select Notifications based on Data field in laravel

Of course, If you want to do more than one clause of course, you can.

For further reading about JSON inline path operator

Thank You ♥

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade