Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

romido's avatar

Route not defined.

I get the error:

Route [books.show] not defined.

Route in web.php:

Route::get('books/{id}', [BooksController::class, 'show'])->name('books.show');

In BookController.php:

 public function show($id)
    {
        $book = Book::find($id);
        if ($book === null) {
            abort(404, "No book has been found.");
        }

        return view('books.show', compact('book'));
    }

link in index.blade.php:

<a  class="btn btn-light m-1" href="{{route('books.show', $book['id'])}}">Read more</a>

About an hour ago this was all still working. I added some functions to the bookController.php (like the update and delete function) and then it stopped working and gives me this error now.

When i type in the url (ex: http://website.test/books/1) i get a blank page.

Does anyone know what i did wrong?

0 likes
14 replies
automica's avatar

@robinmvdoorn

About an hour ago this was all still working. I added some functions to the bookController.php (like the update and delete function) and then it stopped working and gives me this error now.

can you show your whole controller and routes?

run

php artisan route:list

in terminal and you should see what routes are defined.

its possible that you have some clashing in routes.

1 like
automica's avatar

@robinmvdoorn if what is in your repo is correct, you have duplicated your names for 2 routes. I would suggest you rename one of them and see if that fixes your issue and it may also be worth calling the index books.index as you have used dot notation for your other routes.

Route::get('/', [BooksController::class, 'index'])->name('books');

Route::get('/books', [BooksController::class, 'index'])->name('books');
1 like
romido's avatar

All my routes:

Route::get('/', [BooksController::class, 'index'])->name('books');
Route::get('/books', [BooksController::class, 'index'])->name('books');
Route::get('books/create', [BooksController::class, 'create'])->name('books.create')->middleware('auth','admin');
Route::post('books/store', [BooksController::class, 'store'])->name('books.store');
Route::get('books/{id}', [BooksController::class, 'show'])->name('books.show');
Route::get('books/{id}/edit', [BooksController::class, 'edit'])->name('books.edit');
Route::patch('books/{id}', [BooksController::class, 'update'])->name('books.update');
Route::get('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

Route::post('/books/{book}/comments', [CommentsController::class, 'store'])->name('comments.store');

Route::get('/home', [BooksController::class, 'index'])->name('home');
nafeeur10's avatar

@robinmvdoorn,

May be you are under a Middleware like admin or others. Then your Route name will be admin.books.show

Or

Run these commands:

php artisan cache:clear
php artisan route:clear
5 likes
MichalOravec's avatar
Level 75

You have there same route more time

Route::get('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

Problem is get here, it should be delete

https://laravel.com/docs/8.x/routing#available-router-methods

Route::delete('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

By the way you can use resource controllers.

Docs: https://laravel.com/docs/8.x/controllers#resource-controllers

And look on this table, it shows you how it should look like

https://laravel.com/docs/8.x/controllers#actions-handled-by-resource-controller

4 likes
automica's avatar

@robinmvdoorn so you are renaming the first books.show route as books.destroy

Route::get('books/{id}', [BooksController::class, 'show'])->name('books.show');
Route::get('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');
romido's avatar

This worked for me, thank you!

Dirk313's avatar

this also solved one of my problems i had

surony's avatar

You can run just one comment php artisan optimize

Please or to participate in this conversation.