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()))
.
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!
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.
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.
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:
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(...).
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..!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community