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

时间:2016-12-24 16:10:28

标签: php laravel laravel-5.3

将背包用于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

我尝试过就像文档告诉你的那样(在控制器中):

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()

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

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

1 个答案:

答案 0 :(得分:0)

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

尝试