Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vipin93's avatar
Level 13

Serialization of 'Closure' is not allowed?

I tried to dispatch job for my app but its giving me errors

Serialization of 'Closure' is not allowed

here is my in controller

dispatch(new AuthSendMessage($students,$r,$user));

and my AuthSendMessage

class AuthSendMessage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

     protected $students;
     protected $r;
     protected $user;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($students,$r,$user)
    {
       
        $this->students      = $students;
         $this->r                  = $r;
         $this->user            = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        foreach ($this->students as $student)
         {       
            $data = [
         
             'student_id'       => $student->id ,
             'teacher_id'       => null,
             'by_owner_id'   => Auth::id(),
             'by_teacher_id' => null,
             'message'          => $this->r->message

            ];

                $numbers[] = $student->emer_no; 
          
                $this->user->messages()->create($data);
         }
    }

0 likes
3 replies

Please or to participate in this conversation.