• Published:May 7th, 2014
  • Category:Lavarel4

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 }}

Rss Comments


  1. Wow thank you so much. I was really scratching my head.

    #1 Grant
  2. Hi! this is very annoying, ¿know you the reason of this behavior?
    I can’t find anything related to this on Laravel’s documentation.

    #2 MasterZero
  3. Thanks a lot! 🙂
    It words.

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

    #3 marlo
  4. 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.

    #4 Connor
  5. 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…


    #5 derrick
  6. This was driving me nuts.
    Thank you for this. It saved my bacon.

    #6 FuturShoc
  7. Thank you man, it works

    #7 Hicham
  8. Thanks a lot

    #8 deebo
  9. Thank you so much. It worked for me.

    #9 Akhilesh Darjee

Leave a comment

Wordpress.org clearPaper by CreativeBits.it Copyright © 2012-2019 Robin Brackez. All rights reserved. By visiting this site you agree to accept cookies that are purely used to check how many visitors I have. Theme by: creativebits. Custom adaptations by Robin Brackez.