Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel:ArgumentCountError: Too few arguments to function App\Mail

I failed to make the email queue. Not sure what is wrong as I keep getting the error.

‘ArgumentCountError: Too few arguments to function
App\Mail\TransactionSuccess::__construct()’.

What I’m trying to do is to pass the $trx variable when sending emails.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TestController.php

class TestController extends Controller
{
    public function sendtrx(){
        $trx = Transaction::find('123');

        dispatch(new TrxEmailJob($trx));
    }
}

Jobs/TrxEmailJob.php

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

    protected $trx;

    public function __construct(Transaction $trx)
    {
        $this->trx = $trx;
        // dd( $this->trx);
    }

    public function handle()
    {
        Mail::to($this->trx['user_email'])->send(new TransactionSuccess());
    }
}

Mail/TransactionSuccess.php

class TransactionSuccess extends Mailable
{
    use Queueable, SerializesModels;

    public $trx;

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

    public function build()
    {
        return $this->view('Hey Test')
            ->markdown('emails.transactionsuccess');
    }
}

I expect to send an email with details from $trx; however, the job fails based on the table.

ArgumentCountError: Too few arguments to function
App\Mail\TransactionSuccess::__construct(), 0 passed in
/Users/hey/testcode/app/Jobs/TrxEmailJob.php on line 37 and exactly 1
expected in /Users/hey/testcode/app/Mail/TransactionSuccess.php:20
Stack trace:

>Solution :

Update the handle() method to the following.

public function handle()
{
    Mail::to($this->trx['user_email'])
        ->send(new TransactionSuccess($this->trx));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading