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

ybert's avatar
Level 1

Notifications without Eloquent User Model

Hello everybody, I am new here and quite new to Laravel too.

I have to build a notification system for the main website of my company. (for example to display new messages between users). We use Laravel, but we don't use Eloquent models.

So I dont want to reinvent the wheel, but I can't find a way to use Laravel notifications without extending Model class from Eloquent.

I followed this documentation: https://laravel.com/docs/5.6/notifications I want my notifications to be stored in database and to be sent by email. I made my Notification class but I can't use the notify method and I can't use the notifications and unreadNotifications attributes as I don't extend Model from my User class.

I would be very grateful for your help as I can't find a simple solution on the web.

0 likes
6 replies
bobbybouwmann's avatar

An alternative is using the on-demand notifications: https://laravel.com/docs/5.5/notifications#on-demand-notifications

Documentation: https://laravel.com/docs/5.5/notifications#on-demand-notifications

Note: I'm not sure if you can get away using the on-demand notifications using the database without an Eloquent model.

You can also build your own notification system using something like this: https://medium.com/@patrick.proulx/sending-slack-notifications-to-yourself-or-to-your-team-in-laravel-5-x-using-a-webhook-7b95c932c635

2 likes
ybert's avatar
Level 1

Thank you for your help. Do you know how to deal with database notification with the on-demand notifications and without Eloquent Model?

martinbean's avatar

@ybert I don’t think it really matters if you’re using Eloquent or not.

Without digging into the code, when you apply the Notifiable trait to a class, it then attempts to call methods on the class such as routeNotificationsForMail(), so you will just need to implement those methods in your non-Eloquent classes. In fact, it might be better to just implement the RoutesNotifications trait only.

You will need to change how you access the database notifications, though. You won’t be able to call $yourClass->notifications, for instance.

2 likes
ybert's avatar
Level 1

@martinbean Thank you. You helped me a lot.

I tried to implement my own routeNotificationForDatabase method in my user class:

    public function routeNotificationForDatabase($notification = null)
    {
        $databaseNotification = new DatabaseNotification([
            'notifiable_id' => $this->getId(),
            'notifiable_type' => get_class($this)
        ]);
        return $databaseNotification;
    }

The problem is it doesn't fill notifiable_id and notifiable_type fields in the db. The other fields are correctly setted.

Please or to participate in this conversation.