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.3] Fix serialization mistake on notifications #15106

Merged
merged 2 commits into from
Aug 28, 2016
Merged

[5.3] Fix serialization mistake on notifications #15106

merged 2 commits into from
Aug 28, 2016

Conversation

spyric
Copy link
Contributor

@spyric spyric commented Aug 28, 2016

If we will use next notification:

<?php

namespace App\Notifications\Users;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class NewColleague extends Notification
{
    /**
     * @var
     */
    public $colleague;

    /**
     * Create a new notification instance.
     * @param User $colleague
     */
    public function __construct(User $colleague)
    {
        $this->colleague = $colleague;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [
            'broadcast',
            'database',
        ];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'text' => 'We have new colleague, his name is ' . $this->colleague->name,
            'icon' => 'fa fa-user-plus',
            'link' => route('employees.show', [$this->colleague]),
        ];
    }
}

It throw an Exception because when It execute toArray for database, $this->colleague is serialized. I think caused by Broadcast job creating.

If you swap database and broadcast all will be fine.

This patch fixes this issue

@taylorotwell taylorotwell merged commit cb58a4d into laravel:5.3 Aug 28, 2016
@spyric spyric deleted the spyric-patch-1 branch August 28, 2016 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants