Search code examples
phplaravelurlroutesadmin

Laravel generate the routes using Route::resource need to add prefix /admin/


For example , I have a routes that is for the admin page to manage books, a route is set like this:

Route::resource('books','Admin\BookController');

It generated few routes for insert / update/ delete etc... automatically

/books/create
/books/1/edit

The problem is , it is admin page and I would like the link to be

/admin/books/create 
/admin/books/1/edit

How to specific the resource to be admin one ? it auto have prefix of /admin/ Thanks

Updated:

enter image description here

enter image description here


Solution

  • If you need prefix for a multiple routes, you should use route group:

    Route::group(['prefix' => 'admin'], function()
    {
        Route::resource('books','Admin\BookController');
    });
    

    Or, if you need to use just one controller, you could just do this:

    Route::resource('/admin/books','Admin\BookController');