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

helpmyworld's avatar

I need to understand Route and URL

My situation is that when I, for example, create a post or add data in the database. I have the following challenge.

I have the following route and controller.

Route::resource('books', 'BooksController')

I want to use /books/create (This returns an error to say "Page you are looking for could not be found"

 It work when I use 

 Route::match(['get','post'],'/admin/add-book','BooksController@addBook');

{{ url('/admin/add-book')}}

I want to use the former (This: book/create or books.create) but I don't get the view or page.
0 likes
7 replies
TutanRamon's avatar

Otherwise, please try a slash before books

Route::resource('/books', 'BooksController')
helpmyworld's avatar
   <a href="{{ route('books.create')}}">Add Ebooks ( I want this but it says the page is not found) Route::resource('books', 'BooksController')

public function create() {
        
return view('books.create', compact('category'));
}

I PREFERE THE ABOVE METHOD THAN THE BELOW. Which says the page is not found

   <a href="{{ url('/admin/add-book')}}">Add Ebook (This works well but i loose the books.store method)
Route::match(['get','post'],'/admin/add-book','BooksController@addBook');

public function addBook(Request $request){
return view('admin.books.add_book')->with(compact('categories_drop_down'));


In my resources/view - i have admin/book/ and create, index, show blades, and also add_book.blade.php
MichalOravec's avatar

Could you post whole your web.php where are your routes?

helpmyworld's avatar

Thank you, please understand that I Am trying to understand the difference between the two. Just because i have two routes does not mean I use them both.

// Admin Ebook Routes
    Route::resource('books', 'BooksController'); ------- (I PREFRE TO USE THIS SINCE IT GIVE ME ADVANTAGE OF THE STORE METHOD WHEN I CREATE BOOK BUT IT SEEMS NOT TO WORK)
     
    Route::match(['get','post'],'/admin/add-book','BooksController@addBook');
    Route::match(['get','post'],'/admin/edit-book/{id}','BooksController@editBook');
    Route::get('/admin/delete-book/{id}','BooksController@deleteBook');
    Route::get('/admin/view-books','BooksController@viewBooks');
    Route::get('/admin/delete-book-image/{id}','BooksController@deleteBookImage');
MichalOravec's avatar
Level 75

It seems you need to add admin to your route.

Route::resource('admin/books', 'BooksController');
helpmyworld's avatar

Just like that my headache is gone. Thank you. It is working.

1 like

Please or to participate in this conversation.