I have a laravel project. I can basically do CRUD operations about meetings. So i want to add duplicate meeting button that duplicates the meeting with unique meeting id. I created new get route "admin/duplicate/meeting/{meeting}"
and i created duplicate_meeting method in my AdminController. Finally added a button on my blade templates and gave the route. But when i click the button it shows me 404. Here is my web.php file:
Route::get('/admin/meeting/history', [AdminController::class, 'meetingHistory'])->name('admin.meeting.history');
Route::get('/admin/meeting/add', [AdminController::class, 'meeting_add'])->name('admin.meeting_add');
Route::post('/admin/meeting/add', [AdminController::class, 'do_meeting_add'])->name('admin.do_meeting_add');
Route::get('/admin/meeting/edit/{id}', [AdminController::class, 'meeting_edit'])->name('admin.meeting_edit');
Route::post('/admin/meeting/edit', [AdminController::class, 'do_meeting_edit'])->name('admin.do_meeting_edit');
Route::get('/admin/meeting/delete/{id}', [AdminController::class, 'meeting_delete'])->name('admin.meeting_delete');
Route::get('/admin/meeting/duplicate/{meeting}', AdminController::class,'meeting_duplicate')->name('admin.meeting_duplicate');
And AdminController.php:
public function meeting_duplicate(Meeting $meeting)
{
$newMeeting = $meeting->replicate();
$newMeeting->meeting_id = uniqid(); // Generate a unique meeting ID
$newMeeting->created_by = auth()->user()->name; // Set the creator of the new meeting to the current user
$newMeeting->created_by_mail = auth()->user()->email; // Set the creator's email of the new meeting to the current user
$newMeeting->joined = 1; // Set the joined status to 1
$newMeeting->save();
// Redirect to the newly duplicated meeting
return redirect()->route('admin.meeting')->withSuccess('Meeting duplicated successfully.');
}
Finally my meeting.blade.php:
<a class="dropdown-item" href="/admin/meeting/duplicate/{{ $meeting->meeting_id }}">Duplicate Meeting</a>
Can you help me about this issue?
2
Answers
I recommend you to make multi authentication.
It’s not difficult, it just required you to understand authentication module.
Reference here. IlluminateFoundationAuthAuthenticatesUsers
I hope it could help you.
The main reason for 404 error might be from another route that is above your duplicate route. Something like:
Check if you have a route like this (not exactly, but as a pattern), if so, move this line:
above that line.