Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Jobs Serialization of 'Closure' is not allowed

Tags:

php

laravel

jobs

I would like to send Data to a NewsletterStore Job. But it's failing with the following error. Any suggestions?

I also tried to remove the SerializesModels Models trait. Without any success.

Error

Exception
Serialization of 'Closure' is not allowed

Controller

 public function store(StoreNewsletterRequest $request)
    {
        StoreNewsletterJob::dispatch($request);

        return view('backend.dashboard.index');
    }

Job

protected $request;

    public function __construct($request)
    {
        $this->request = $request;
    }

    /**
     * Execute the job.
     *
     * @return void
     */

    public function handle()
    {
        if(!Newsletter::isSubscribed($this->request->email))
        {

            Newsletter::subscribe($this->request->email, [

                config('newsletter.list_fields.firstname') => $this->request->firstname,
                config('newsletter.list_fields.lastname') => $this->request->lastname

            ]);
        }
    }
like image 564
Stan Barrows Avatar asked Mar 07 '18 17:03

Stan Barrows


1 Answers

Another possibility for this if you still want access to many of the familiar methods 'only, get' etc you can just

collect($request->all());

And use it as a collection instead

like image 60
MHewison Avatar answered Nov 13 '22 06:11

MHewison