In my view, why is the variable $userId undefined inside the button? I tried to make a print layout of absent history, but I need help finding this error.
<a href="{{ route('attendance.print', ['user' => $userId]) }}" class="btn btn-primary btn-sm">
<x-tabler-download class="icon-4 mr-1"/>
<span>Download rekap</span>`
</a>
Route
Route::middleware('auth')->group(function () {
Route::middleware('can:attendance.index')->get('/attendance', \App\Livewire\Pages\Attendance\Index::class)->name('attendance.index');
Route::middleware('can:attendance.mine')->get('/attendance/mine', \App\Livewire\Pages\Attendance\Mine::class)->name('attendance.mine');
Route::middleware('can:attendance.print')->get('/attendance/printAttendance/{user}', \App\Livewire\Pages\Attendance\PrintAttendance::class)->name('attendance.print');
});
Controller
class PrintAttendance extends Component
{
public $userId;
public $attendances;
public function mount($user)
{
$this->userId = $user;
$this->loadAttendances();
}
public function loadAttendances()
{
$this->attendances = Attendance::where('user_id', $this->userId)->where('approved', 1)->get();
}
public function render()
{
return view('livewire.pages.attendance.print-attendance', ['userId' => $this->userId,]);
}
}