我没能让邮箱排队.我不确定哪里出了问题,因为我一直收到错误.

‘ArgumentCountError:函数的参数太少 App\Mail\TransactionSuccess::__Construct()‘.

我想要做的是在发送邮箱时传递$trx变量.

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');
    }
}

我希望发送一封邮箱,其中包含$TRX的详细信息;然而,根据表,该作业(job)失败了.

ArgumentCountError:函数的参数太少 App\Mail\TransactionSuccess::__Construct(),传入0 /USERS/嘿/Testcode/app/Jobs/TrxEmailJob.php位于第37行和第1行 预计在/Users/hey/testcode/app/Mail/TransactionSuccess.php:20中 堆栈跟踪:

推荐答案

将Handle()方法更新为以下内容.

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

Php相关问答推荐

Laravel 10查询中的多个where子句

使用额外的输入字段自定义WooCommerce单个产品

在函数内部获取一致的单选按钮值以更新WordPress用户数据

WooCommerce我的帐户:从帖子作者处获取自定义帖子类型帖子ID

在WooCommerce管理中 for each 运输方法设置添加自定义字段

这是在可召回的背景下吗?

根据类别的数量折扣更改WooCommerce购物车商品价格

PHP Match如何准确判断条件?

如何在codeigniter中将order_by RAND与下面的代码一起使用

$this->;db->;update();CodIgnitor中的功能不工作

根据小计向 WooCommerce Checkout 添加佣金

奇怪的 preg_match_all() 行为

使用 foreach php 将记录正确分配给正确的父级

WooCommerce 订单和邮箱通知的自定义产品描述

在WooCommerce购物车和 checkout 页面中更改总计文本

WooCommerce订单支付页面上的附加支付订单按钮

如何通过额外的属性和本地化来使用 laravel 枚举

我怎样才能在 .htaccess 中有 2 个参数?

PHP Remedy API 调用以创建附件无效的条目(使用 Postman Works!)

无法按今天加上 7 天显示数据库项目