Can you please show your job class?
Apr 30, 2020
7
Level 15
What triggers `Serialization of 'Closure' is not allowed` when using Queue?
This is from abstract class Queue
/**
* Create a payload for an object-based queue handler.
*
* @param object $job
* @param string $queue
* @return array
*/
protected function createObjectPayload($job, $queue)
{
$payload = $this->withCreatePayloadHooks($queue, [
'displayName' => $this->getDisplayName($job),
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
'maxTries' => $job->tries ?? null,
'delay' => $this->getJobRetryDelay($job),
'timeout' => $job->timeout ?? null,
'timeoutAt' => $this->getJobExpiration($job),
'data' => [
'commandName' => $job,
'command' => $job,
],
]);
return array_merge($payload, [
'data' => [
'commandName' => get_class($job),
'command' => serialize(clone $job), // this line is where the exception is thrown
],
]);
}
In my particular case I have an InvitationsRegisterController that has an invitation code.
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
$invitation = Invitation::findByInvitationCode(request('invitation_code'));
abort_if($invitation->hasBeenUsed(), 404);
return Validator::make($data, [
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:12|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$invitation = Invitation::findByInvitationCode(request('invitation_code'));
$user = User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$invitation->update([
'user_id' => $user->id,
]);
return redirect('/email/verify');
}
Level 15
@nakov really appreciate your taking a stab at this. It helped me think about other possibilities. In the end, at least it appears, the InvitationsController was using the out of the box Laravel register method. I mistakenly believed I could reuse it.
From what I can see the route cannot be used twice.
The error message is not sufficiently descriptive - possibly worth doing a PR on github and try to improve the message.
So, in the InvitationsController I omitted the protected function validator(array $data) and condensed it to:
/**
* Create a new user instance after a valid registration.
*
* @param Request $data //changed from array $data
* @return User
*/
protected function create(Request $data) //changed from array $data
{
$invitation = Invitation::findByInvitationCode(request('invitation_code'));
abort_if($invitation->hasBeenUsed(), 404);
request()->validate([
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:12|confirmed',
]);
$user = User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
event(new Registered($user)); // a key addition
$invitation->update([
'user_id' => $user->id,
]);
return view('auth.verify');
}
Please or to participate in this conversation.