Support the ongoing development of Laravel.io →
Mail Queues
Last updated 1 year ago.
0

When queueing, data is being serialized, so one thing you could try is to not pass any class objects to the view, just arrays of plain data. If serializartion of the user object failed silently, that might explain why it's not what you expect in the view. Maybe cast the User object to an StdClass by doing json_decode(json_encode($user->toArray())).

Last updated 1 year ago.
0

Good idea, I'll try that and see if it works. I suspect that the problem occurs when unserializing, since it works fine when I don't use queues.

Thanks!

Last updated 1 year ago.
0

Ok, the problem seems to be the serialization after all. Well, actually, there is no actual serialization for what I can see, it just does this:

json_encode(array('job' => $job, 'data' => $data));

$data contains my User instance, and when json-encoding it this way it turns out like this:

{"data":{"medic":{"errors":null,"incrementing":true,"timestamps":true,"exists":false}}}

So I guess I should do what you say or implement the JsonSerializable interface on my model (or better yet, the base model)

I'll try that and see if it works, but I think any of these solutions should do the trick.

Last updated 1 year ago.
0

Well, it didn't work, the serialization worked fine this time though. But now that I think about it, the error says "Trying to get property of non-object" so it doesn't matter if the serialization was wrong, because it was receiving an object (even if it was a wrong one) so, the actual problem is not the serialization, but that it's not receiving the $data array correctly, or something like that.

I'll continue to poke around to see if I can find out what I'm getting.

Last updated 1 year ago.
0

Ok! I got it! The problem was that IronJob's fire method is doing this:

$this->resolveAndFire(json_decode($this->getRawBody(), true));

Which is fine, but it means that the view will always receive an associative array. I get why this is desirable, but I then I should change my email views to access the model's attributes as an array (which, luckily, works fine with Eloquen models as well).

I made that change (I had several notifications which included relations as well, so I had to eager load them) and it worked!

I also implemented the JsonSerializable interface in my base model like this:

https://gist.github.com/xFlatlinex/8220543

Last updated 1 year ago.
0

Just for the record...

At this time Eloquent already implements JsonSerializable interface, so the only thing you need to do is access your data as associative array within your view if you're using Mail::queue(...).

0

sahibalejandro said:

Just for the record...

At this time Eloquent already implements JsonSerializable interface, so the only thing you need to do is access your data as associative array within your view if you're using Mail::queue(...).

Thank-you sahibalejandro, this is my accepted answer as I had the same problem... I thought Mail:queue was rendering the html before sending the queue but it looks like is is done when Iron executes it.. SO use: $var['info1'] instead of $var->info1 in your queued email views..!

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

xFlatlinex xflatlinex Joined 18 Dec 2013

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.