0

I have a problem with email's views with Laravel. This is how I send a mail:

$user = $bet->user; // A bet hasOne user. All is ok here

Mail::queue('emails.betWon', array('user' => $user), function($message) use ($user)
{
    $message->to($user->email)->subject('Tu as remporté un pari !');
});

This is my view emails.betWon:

<!DOCTYPE html>
    <html lang="fr">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        {{ var_dump($user) }}
    </body>
</html>

And this is the mail I get:

array (size=3)
  'timestamps' => boolean false
  'incrementing' => boolean true
  'exists' => boolean true

Which is not a User object...

1 Answer 1

0

Because you are using Mail::queue you cannot send an object to the queue, as data is being serialized. You need to convert it to an array first.

change

$user = $bet->user;

to

$user = $bet->user->toArray();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.