I keep encountering this error on Laravel 8 with PHP 8. Im grabbing the id from the view like so:
<button type="submit">
<a href="{{route('employees.payslip', $employee->id)}}" class="text-green-600 hover:text-green-900">Payslip</a>
</button>
This then goes to web.php like so:
Route::get('employees/{id}/payslip', ['App\Http\Controllers\PrintController', 'print'])->name('employees.payslip');
It then goes to the print function like so:
public function print($id)
{
$employees = Employees::findOrFail($id);
$teams = Team::all();
return view('employees.payslip',compact('employees', 'teams'));
}
When i remove the return view line and replace it with:
dd($employees);
It gives me the correct information but when i keep the line:
return view('employees.payslip',compact('employees', 'teams'));
and send it the view 'employees.payslip': it gives me the error: anyone has any ideas?
@forelse($employees as $employee)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->name}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->surname}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->address}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->phone}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->role}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{$employee->absent}}
</td>
</tr>
@empty
<td>
No Information to Display
</td>
@endforelse
$employeesis a single model, not a collection of Employees. You're currently trying to loop through the properties of a single Employee. Remove the loop and it should work