Laravel 5.3 - 无法通过mailable传递数据

问题描述 投票:0回答:1

用背包做laravel。

这就是我的控制器的样子:

public function store(StoreRequest $request)
{
    $finance = $request->all();
    if ($request->input('shouldPay') == 'Yes') {
        Mail::to($request->user())->send(new NewBill($finance));
        return parent::storeCrud();
    } 
    else {
        return parent::storeCrud();
    }
}

这就是我的可邮寄NewBill的样子:

class NewBill extends Mailable
{
 use Queueable, SerializesModels;


/**
 * The finance instance.
 *
 * @var finance
 */
public $finance;


/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct()
{
    //
    $this->finance = $finance; //THIS IS LINE 31
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('emails.newbill');
}
}

这是错误:

ErrorException in NewBill.php line 31:
Undefined variable: finance

我试过像doc告诉你的那样(在控制器中):

public function store(StoreRequest $request, $financeId)
{

    $finance = Finance::findOrFail($financeId);
    if ($request->input('shouldPay') == 'Yes') {
        Mail::to($request->user())->send(new NewBill($finance));
        return parent::storeCrud();
    } 
    else {
        return parent::storeCrud();
    }
}

结果:

Missing argument 2 for App\Http\Controllers\Admin\FinanceCrudController::store()

我认为从商店功能发送电子邮件更容易,而不是通过可邮寄,这可能吗?

如果没有,我该如何解决问题呢?

php laravel laravel-5.3
1个回答
0
投票
public function __construct($finance)
{
    $this->finance = $finance;
}

试试这个

© www.soinside.com 2019 - 2024. All rights reserved.