Skip to content
Advertisement

How to add model to laravel notifications and access it with eloquent?

I created a laravel notification class with

php artisan make:notification NewUserNotification

JavaScript

then made a custom DbChannel to add order id

JavaScript

Everything is working perfectly, I am able to access Auth::user->notifications but not the order, I have the order_id as a foreign key and able to access the order in phpMyAdmin by clicking on it, I’ve tried this but its giving me null

$notifications->order

Advertisement

Answer

You could use $order = Order::find($data['order_id']) presuming you have the Order class imported into your namespace. I think that’s probably the simplest way.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement