Calling job class from controller not passing param

Posted 11 months ago by RIAengine

Somehow I'm getting an error that:

Too few arguments to function App\Jobs\ProcessMail::handle(), 0 passed and exactly 1 expected

But I'm passing the parameter. Code in ProcessMail:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Mail;
use App\Mail\AdvAndPrivacyMailer;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $emailto;

    public function __construct()
    {
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle($emailto)
    {

        Mail::to($emailto)->queue(new AdvAndPrivacyMailer());

    }
}

And the relevant bit of code from my controller which is calling this job:

                $clients_table = Auth::user()->__get('clients_table');

                $user = DB::table($clients_table)->where('email', $emailto)->value('id');
                if (!($user == NULL))
                {

                    dispatch(new ProcessMail($emailto));

                    $message = "email was sent to ".$emailto;
                    return view('home')->with('message', $message);

                }

I'm probably doing something wrong. Any thoughts?

Please sign in or create an account to participate in this conversation.