Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 715
user782104 Avatar asked Sep 12 '25 08:09

user782104


2 Answers

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');
like image 186
Alexey Mezenin Avatar answered Sep 13 '25 21:09

Alexey Mezenin


Change your route to

Route::resource('admin/books','Admin\BookController');
like image 33
Shalu Singhal Avatar answered Sep 13 '25 22:09

Shalu Singhal