Search code examples
laravelrouteshttp-status-code-404

Laravel 5.7 route create systematically produced 404 Sorry, the page you are looking for could not be found


My 'create' route always produces a 404 error, when I use http://localhost:8000/books/create

my routes/web.php file contains:

Route::middleware('role:adm|user')->group(function () {

Route::get('books', 'BooksController@index')->name('books.index');
Route::get('books/{book}', 'BooksController@show')->name('books.show');
Route::get('books/{book}/edit', 'BooksController@edit')->name('books.edit');
Route::put('books/{book}', 'BooksController@update')->name('books.update');

});

Route::middleware('role:adm')->group(function () {

Route::get('/books/create', 'BooksController@create')->name('books.create');
Route::post('books', 'BooksController@store')->name('books.store');
Route::delete('books/{book}', 'BooksController@destroy')->name('books.destroy');

});

Oddly, if I delete the 'show' route, the 'create' route works properly

Thank you in advance


Solution

  • /books/create technically matches the books/{book} syntax, and is matching that. Things will likely work if you define the /books/create route first which should put it in the routes table earlier.