[英]Barryvdh/laravel-domPDF returning Attempt to read property "name" on bool
Im using Laravel 8 with PHP 8 as well as barryvdh/laravel-domPDF.我使用 Laravel 8 和 PHP 8 以及 barryvdh/laravel-domPDF。 I have a crud that displays employee information and you can print out their payslips.
我有一个显示员工信息的杂物,您可以打印出他们的工资单。 When i dont pass through the $id it works correctly and prints all the employees information however when i do it returns the error:
当我不通过 $id 它可以正常工作并打印所有员工信息但是当我这样做时它会返回错误:
Attempt to read property "name" on bool
尝试在 bool 上读取属性“名称”
This is my route:这是我的路线:
Route::get('/print/{id}', ['App\Http\Livewire\EmployeesTable', 'print'])->name('livewire.employees-table.print');
This is my model function这是我的 model function
public function print($id){
$employees = Employees::find($id);
$teams= Team::all();
$pdf = PDF::loadView('employees.payslip', compact('teams', 'employees'));
return $pdf->download('invoice.pdf');
}
This is my user relationship:这是我的用户关系:
public function employees(){
return $this->hasMany(Employees::class);
}
This is my employees relationship:这是我的员工关系:
public function user(){
return $this->belongsTo(User::class);
}
. .
<thead>
@foreach ($employees as $employee)
<tr>
<td>
{{$employee->name}} {{$employee->surname}}
{{$employee->phone}}
{{$employee->role}}
</td>
</tr>
@endforeach
</thead>
<thead>
@foreach ($teams as $team)
<tr>
<td>
{{$team->companyName}}
{{$team->street}}
{{$team->compound}}
{$team->suburb}}
{$team->phone}}
</td>
</tr>
@endforeach
</thead>
</table>
I think $employees
return empty result so better check before looping我认为
$employees
返回空结果,所以在循环之前更好地检查
@if(isset($employees)&&count((array)$employees))
@foreach ($employees as $employee)
<tr>
<td>
{{$employee->name}} {{$employee->surname}}
{{$employee->phone}}
{{$employee->role}}
</td>
</tr>
@endforeach
@endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.