Here is my Routes
Route::get('/admin/dashboard', function () {
$attendances = Attendance::with('staff')->orderBy('time', 'desc')->get();
return view('admin.dashboard', compact('attendances'));
})->name('admin.dashboard');
Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/admin', [AdminController::class, 'dashboard'])->name('admin.dashboard');
});
Route::get('/admin/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');
Route::get('/admin/dashboard', function () {
return view('admin.dashboard');
})->name('admin.dashboard');
Route::post('/attendance/scan', [AttendanceController::class, 'scan'])->name('attendance.scan');
AdminController
The controller does not give errors so I think the mistake might come from the dashboard part of the codes.
public function dashboard()
{
$attendances = Attendance::with('staff')->orderBy('time', 'desc')->get();
return view('admin.dashboard', compact('attendances'));
}
Here is the blade view. dashboard.blade.php I do not get error from the controller so I think the mistake might come from the this part of the codes.Maybe I used to attendance wrongly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
@livewireStyles <!-- Required for Livewire -->
</head>
<body>
<h1>Admin Dashboard</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Location</th>
<th>Time</th>
</tr>
</thead>
<tbody>
@foreach ($attendances as $attendance)// The error points at this line
<tr>
<td>{{ $attendance->staff->name }}</td>
<td>{{ ucfirst($attendance->type) }}</td>
<td>{{ $attendance->location }}</td>
<td>{{ $attendance->time }}</td>
</tr>
@endforeach
</tbody>
</table>
<!-- Embed the StaffManager Livewire Component -->
@livewire('staff-manager')
@livewireScripts <!-- Required for Livewire -->
</body>
Here is my Routes
Route::get('/admin/dashboard', function () {
$attendances = Attendance::with('staff')->orderBy('time', 'desc')->get();
return view('admin.dashboard', compact('attendances'));
})->name('admin.dashboard');
Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/admin', [AdminController::class, 'dashboard'])->name('admin.dashboard');
});
Route::get('/admin/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');
Route::get('/admin/dashboard', function () {
return view('admin.dashboard');
})->name('admin.dashboard');
Route::post('/attendance/scan', [AttendanceController::class, 'scan'])->name('attendance.scan');
AdminController
The controller does not give errors so I think the mistake might come from the dashboard part of the codes.
public function dashboard()
{
$attendances = Attendance::with('staff')->orderBy('time', 'desc')->get();
return view('admin.dashboard', compact('attendances'));
}
Here is the blade view. dashboard.blade.php I do not get error from the controller so I think the mistake might come from the this part of the codes.Maybe I used to attendance wrongly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
@livewireStyles <!-- Required for Livewire -->
</head>
<body>
<h1>Admin Dashboard</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Location</th>
<th>Time</th>
</tr>
</thead>
<tbody>
@foreach ($attendances as $attendance)// The error points at this line
<tr>
<td>{{ $attendance->staff->name }}</td>
<td>{{ ucfirst($attendance->type) }}</td>
<td>{{ $attendance->location }}</td>
<td>{{ $attendance->time }}</td>
</tr>
@endforeach
</tbody>
</table>
<!-- Embed the StaffManager Livewire Component -->
@livewire('staff-manager')
@livewireScripts <!-- Required for Livewire -->
</body>
Share
Improve this question
edited Jan 19 at 22:03
matiaslauriti
8,1224 gold badges36 silver badges47 bronze badges
asked Jan 19 at 19:30
Anyabour PeterAnyabour Peter
397 bronze badges
1 Answer
Reset to default 1You have 3 routes pointing to the same url '/admin/dashboard'. Laravel will ideally pick the last one defined which in this case doesn't point to the AdminController. I would say to take off the first and last routes pointing to the same url and leave the
Route::get('/admin/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');