Dompdf mail with attachment QuotationController
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('[email protected] ','John Doe')->subject('Quotation');
$message->from('[email protected] ','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
}
Error Message
"Undefined variable: quotation"
<form action="{{ route('name', $quotation->id) }}" method="post">
@csrf @method('PATCH')
Sending $quotation->id or $quotation->slug as a second parameter is very important!
@Sergiu17
QuotationsController.php
public function edit(Quotation $quotation)
{
return view('employees.quotations.edit', compact('quotation'));
//return view('employees.quotations.edit')->with('quotation');
}
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
It's already like this , i can't understand what i am doing wrong
Undefined variable: quotation (View: ..path\resources\views\employees\quotations\edit.blade.php)
Route::get('/quotations/{quotation}/edit');
public function edit(Quotation $quotation)
{
$quotation should match with placeholder between { }
// if route
Route::get('quotations/{quotation}/edit');
public function edit(Quotation $quotation) { ... }
// if route
Route::get('quotations/{id}/edit');
public function edit(Quotation $id) { ... }
// if route
Route::get('quotations/{slug}/edit');
public function edit(Quotation $slug) { ... }
Did you get it? hope this is the problem
@Sergiu17 Route already looks like this. Looks like there is something else which cause the problem
Route::get('/quotation/{quotation}/edit', 'Employee\QuotationController@edit')->name('employee.quotation.edit');
@Sergui17 This has something to do with
QuotationController
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('[email protected] ','John Doe')->subject('Quotation');
$message->from('[email protected] ','The Sender');
$message->attachData($pdf->output(), 'filename.pdf');
});
echo 'Email was sent!';
}
}
Specifically the undifined variable $quotation error is shown after the below line
$pdf = PDF::loadView('employees.quotations.edit', $quotation);
Your mistake is using $quotation inside an anonymous function. To fix this you should update:
Mail::send(['text'=>'mail'], $info, function($message){
To:
Mail::send(['text'=>'mail'], $info, function($message) use ($quotation){
and you should be good :)
@zaster can you show me the whole error stack trace?
Please sign in or create an account to participate in this conversation.