Laravel: passing data with Mail:queue() to a view

Mail:send() and Mail:queue() don’t work the same when it comes to passing $data to a view. At least not when you’re passing an eloquent object (or a “model” object).


$data = array();
$data['myObject'] = $eloquentObject;

Mail::send('emails.hello', $data, function($message) use ($toAddress) {

This will pass $data to the view so you can access $myObject in the view.

But when you change Mail::send to Mail::queue the $myObject isn’t accessible as expected. This happens when you’re passing an eloquent (inherited) object. To make this work with queue you have to serialize the $eloquentObject first and later unserialize it in the view.

$data = array();
$data['myObject'] = serialize($eloquentObject);

Mail::send('emails.hello', $data, function($message) use ($toAddress) {

In the view:

{{ $serializedObject->property }}

You May Also Like


  1. Thanks a lot! 🙂
    It words.

    By the way, is it a Laravel Bug? And what serialize does for it to be solved?

  2. Thanks for this man – wasted about 2 hours trying to figure out what was going on. Forgotten I’d changed my mail wrapper from send to queue.

  3. hi, great post came across your post and jumped off my seat. been pondering on whats wrong with my code, am doing an eloquent query and passing the results to the $data var. the problem is i cant access the date element there when i try to iterate through the array .. which i need to do to send out emails with unique message content… i cant seem to find a solution… please help these are the links to the code and the problem in detail…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.