laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.02k forks source link

[5.3] Incorrect Eloquent serialization when sending emails with queued #14579

Closed spyric closed 8 years ago

spyric commented 8 years ago

Here a code that works normal in laravel 5.2

$user = \App\Models\User::find(1);
$data = [
    'previewMessage' => 'Your account have been successfully created',
    'user'           => $user,
];

\Mail::queue('emails.new_employee', $data, function ($message) use ($user) {
    $message
        ->subject('Registration completed')
        ->to($user->email);
});

in emails/new_employee.blade.php in 5.2 you will get an Eloquent model, but in 5.3 you will get an array with attributes.

Is it normal behaviour? Or I shouldn't to pass eloquent model to email view?

GrahamCampbell commented 8 years ago

Or I shouldn't to pass eloquent model to email view?

Yeh, don't do that. If you don't use the sync queue, you'll get a serialization error surely?

spyric commented 8 years ago

I have tried with database driver too... Same result

In database info stores like this: image

So I think it's breaking change and this should eigher be fixed (I tried to do it my self but didn't find a way to fix it) or be mentioned in upgrade docs

GrahamCampbell commented 8 years ago

I'm saying why doesn't it crash on L5.2?

spyric commented 8 years ago

I think because Taylor has changed way to serialization of data.

Here how task looks in Laravel 5.2

image

So I think that in 5.2 ::entity::|App\\User|1 was replaced by object after query to database. In 5.3 we are getting plain object that is not associaded with model

spyric commented 8 years ago

In 8952983 were removed functions:

huglester commented 8 years ago

Almost all the time we use Eloquent model inside the Email template files. So now we will need to move to arrays (when using queues)?

thank you

spyric commented 8 years ago

@huglester I hope no, and @taylorotwell will approve my pull request and all will work like before, because I very often use Eloquents mutators in emails and it's very helpfull.

Also if you will use Mailable way, models will be serialized. Two similar ways and two different results for one action . It's something strange, imho

spyric commented 8 years ago

Fixed by Taylor