My issue is, even if I added route in web.php then also it gives me 404 not found.
My route file as below.
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StudentController;
Route::get('/students', [StudentController::class, 'index'])->name('students.index');
Route::get('students/export/excel', [StudentController::class, 'exportExcel'])->name('students.export.excel');
Route::get('students/export/pdf', [StudentController::class, 'exportPdf'])->name('students.export.pdf');
Route::get('students/{student}', [StudentController::class, 'show'])->name('students.show');
Route::get('/students/create', [StudentController::class, 'create'])->name('students.create');
Route::post('/students/store', [StudentController::class, 'store'])->name('students.store');
If I add my route
Route::get('/students/create', [StudentController::class, 'create'])->name('students.create');
below the route
Route::get('students/{student}', [StudentController::class, 'show'])->name('students.show');
it gives me 404 and if I add my route above the
Route::get('students/{student}', [StudentController::class, 'show'])->name('students.show');
it works fine.
How is it possible? Can anyone explain this or provide the some link so I can understand the how it works?
Thanks in Advance. :)
The route Route::get('students/{student}', ...) is a dynamic route that matches any URL segment after students/. For example:
/students/123 /students/xyz
This means when the route Route::get('students/{student}', ...) is defined before Route::get('/students/create', ...), Laravel tries to match /students/create with students/{student}. It interprets create as the {student} parameter, which likely causes the controller method or validation to fail.
To avoid conflicts between static and dynamic routes, always define specific routes before dynamic ones.