laravel - DOMPDF - Laravel - 带附件的电子邮件 PDF
问题描述
我收到此错误是什么原因
“未定义的变量:引号”
报价控制器.php
public function update(Request $request, Quotation $quotation)
{
{
$quotation->description= $request['description'];
$quotation->qty= $request['qty'];
$quotation->each_price= $request['each_price'];
$quotation->save();
$info = ['info'=>$quotation];
Mail::send(['text'=>'mail'], $info, function($message){
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example@gmail.com','John Doe')->subject('Quotation');
$message->from('from@gmail.com','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
}
public function edit(Quotation $quotation)
{
return view('employees.quotations.edit', compact('quotation'));
//return view('employees.quotations.edit')->with('quotation');
}
..................................................... .....................
路线看起来像这样
Route::post('/quotation', 'Employee\QuotationController@store')->name('employee.quotation.store');
Route::get('/quotation', 'Employee\QuotationController@index')->name('employee.quotation.index');
Route::get('/quotation/create', 'Employee\QuotationController@create')->name('employee.quotation.create');
Route::put('/quotation/{quotation}', 'Employee\QuotationController@update')->name('employee.quotation.update');
Route::get('/quotation/{quotation}', 'Employee\QuotationController@show')->name('employee.quotation.show');
Route::delete('/quotation/{quotation}', 'Employee\QuotationController@destroy')->name('employee.quotation.destroy');
Route::get('/quotation/{quotation}/edit', 'Employee\QuotationController@edit')->name('employee.quotation.edit');
employees.quotations.edit.blade.php 看起来像这样
@section('left-menu')
@endsection
@section('right-menu')
@endsection
@section('content')
<h1>Update a Quotation</h1>
<br><br>
<form action="{{ route('employee.quotation.update',$quotation->id) }}" method="post">
@method('PUT')
@csrf
<div class="form-group">
<label for="inputJobDescription">Description</label>
<textarea class="form-control" rows="2" id="inputQuoteDescription" name="description" placeholder="Description">{{$quotation->description}}
</textarea>
</div>
<div class="form-group row">
<label for="inputQty" class="col-2 col-form-label">Qty</label>
<div class="col-10">
<input type="text" class="form-control" id="inputQty" name="qty" value="{{$quotation->qty}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
</div>
</div>
<div class="form-group row">
<label for="inputEachPrice" class="col-2 col-form-label">Each Price</label>
<div class="col-10">
<input type="text" class="form-control" id="inputEachPrice" name="each_price" value="{{$quotation->each_price}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
@endsection
@section('pagescript')
@stop
我在这里想念什么?我已经将 $quotation 传递给编辑视图
解决方案
您显然没有$quotation
通过您的路线传递变量。您还使用了$quotation
作为对象;这告诉我你不打算通过这条路线。试试下面的代码:
public function update(Request $request, $quotation_id)
{
$quotation = Quotation::findOrFail($quotation_id);
$quotation->description= $request['description'];
$quotation->qty= $request['qty'];
$quotation->each_price= $request['each_price'];
$quotation->update();
$info = ['info'=>$quotation];
Mail::send(['text'=>'mail'], $info, function($message) use ($quotation){
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
$message->to('example@gmail.com','John Doe')->subject('Quotation');
$message->from('from@gmail.com','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
这应该有效。
推荐阅读
- pdf - DocumentView 不包含 TabDocumentLoaded 的定义,并且没有扩展方法 TabDocumentLoaded 接受 DocumentView 类型的第一个参数
- flutter - 多个平面按钮链接到不同的列表视图,然后如何使未选中的按钮变灰(不聚焦)
- windows - 如何以我想要的格式将数字更改为命名月份,例如 11,如 11 月
- python - 如何为标题、摘要和日期选择正确的标签
- python - Python中优化的收敛曲线
- azure - 如何在 Azure 上使用沉浸式阅读器?
- python - 从平面列表中查找所有列表和子列表组合
- monitoring - 基于 Telnet 的 check_mk 检查
- tensorflow-federated - 训练损失还是测试损失?
- apache-nifi - 将敏感参数设置为非敏感属性后NiFi无法启动