Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Add ability to extend DatabaseNotification model attributes on create #23337


None yet
2 participants
Copy link

commented Feb 28, 2018

Building of attributes array for the Illuminate\Notifications\DatabaseNotification model inside Illuminate\Notifications\Channels\DatabaseChannel extracted to method, what allow us to extend or overwrite default attributes.

I found it useful because I were needed to add seen_at and some more attributes related to my application and were needed to extend default DatabaseNotification model. And instead just modifying attributes in DatabaseChannel class on notification creation, we need to copy-paste send method. That means that if there will be changes in send method in the future - we will require to update extended implementations.

With this change we can do:


namespace App\Notification\Channels;

use Illuminate\Notifications\Channels\DatabaseChannel as BaseDatabaseChannel;
use Illuminate\Notifications\Notification;

class DatabaseChannel extends BaseDatabaseChannel
    protected function buildPayload($notifiable, Notification $notification)
        return array_merge(parent::buildPayload($notifiable, $notification), [
            'seen_at' => null,
            'after_updrade' => 'Sleep well',

Additionally it helps us to keep the code DRY.

antonkomarev and others added some commits Feb 28, 2018

@taylorotwell taylorotwell merged commit 4380ac8 into laravel:5.6 Feb 28, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
continuous-integration/styleci/pr The StyleCI analysis has passed

@antonkomarev antonkomarev deleted the cybercog:feature/extend-database-notification-model-payload branch Feb 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.