laravel mail queueing - Insufficient data for unserializing

大兔子大兔子 提交于 2019-12-12 03:08:10

问题


I am using

Ubuntu
laravel 4.2
beanstalked

when i try to

php artisan queue:work

it returns

 [ErrorException]                                                  
  Insufficient data for unserializing - 1403 required, 218 present  

mail function (confide package)

Mail::queueOn(
                    Config::get('confide::email_queue'),
                    Config::get('confide::email_account_confirmation'),
                    compact('user'),
                    function ($message) use ($user) {
                        $message
                            ->to($user->email, $user->username)
                            ->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
                    }
                );

回答1:


I came across this problem as well and I think I've got the solution.

When an email gets queued, Laravel needs to serialize all of the email's data so it can be recalled later on when the queue is being processed.

The problem is that when you try to serialize an instance of an Eloquent model ($user in this case) the serialized string will be too large to be stored in the queue.

To get around this, store the specific values you need in an array before calling Mail::queueOn and attach that array to the closure you pass as an argument to Mail::queueOn.

$data = array(
    'email' => $user->email,
    'username' => $user->username
);

Mail::queueOn(
    Config::get('confide::email_queue'),
    Config::get('confide::email_account_confirmation'),
    compact('user'),
    function ($message) use ($data) {
        $message
            ->to($data['email'], $data['username'])
            ->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
    }
);

I found the solution while looking at this issue in GitHub




回答2:


We had it lately with the same question, but I've found another thing that is wrong:

Config::get('confide::email_queue'),
Config::get('confide::email_account_confirmation'),

and

(Lang::get('confide::confide.email.account_confirmation.subject'));

are not correct. There are no 2 :: to name the file, it is:

Config::get('confide.email_queue');

and so on for all the other declarations!

It is

filename.arraykey


来源:https://stackoverflow.com/questions/28142459/laravel-mail-queueing-insufficient-data-for-unserializing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!