Select Laravel Notification.
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_atWe 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
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 ♥
