I have question and I'm can't find a solution in document
I use command
php aritsan make:controller Backend\ProductController --resource --Model=Model\Product
So, I will need route same location file controller
I use
Route::resource('/backend/product','Backend\ProductController');
after, run a command
php artisan route:list
and this result
But, I don't need this I think should be
+--------+-----------+----------------------------------+-----------------+------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+-----------------+------------------------------------------------------------+------------+
| | GET|HEAD | backend/product | backend.product.index | App\Http\Controllers\Backend\ProductController@index | web |
| | POST | backend/product | backend.product.store | App\Http\Controllers\Backend\ProductController@store | web |
| | GET|HEAD | backend/product/create | backend.product.create | App\Http\Controllers\Backend\ProductController@create | web |
Route name should be backend.product.index
I find a solution. but not happy.
Route::resource('/backend/user','Backend\UserController')->names([
'index' => 'backend.user.index',
'store' => 'backend.user.store',
'edit' => 'backend.user.edit',
'update' => 'backend.user.update',
'destroy' => 'backend.user.destroy',
]);
Documents resource names
Route::resource: The Route::resource method is a RESTful Controller that generates all the basic routes required for an application and can be easily handled using the controller class.
You can define a route to this controller action, as: Route::get('user/{id}', 'UserController@show'); Route::resource: The Route::resource method can be a Restful Controller that produces all the basic routes required for an application and is dealt via controller class.
Creating the Controller This is the easy part. From the command line in the root directory of your Laravel project, type: php artisan make:controller sharkController --resource This will create our resource controller with all the methods we need.
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.
The command for creating Model Controller with resource
php artisan make:controller Backend\ProductController --resource --Model=Model\Product
Change web.php and use prefix
, namespace
, as
Route::group(['prefix' => 'backend','namespace'=>'Backend','as'=>'backend.'], function () {
Route::resource('product','ProductController');
});
Now use
php artisan route:list
backend.product.index
backend.product.create
backend.product.show
backend.product.destroy
backend.product.update
backend.product.edit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With