Reputation: 3635
I have many routes like these :
Route::resource('/dashboard/class', 'classController');
Route::get('/dashboard/class/get-by-filter', 'classController@getByFilter');
Route::get('/dashboard/class/get-by-search', 'classController@getBySearch');
...
...
Route::resource('/dashboard/orders', 'OrderController');
Route::get('/dashboard/orders/get-by-filter', 'OrderController@getByFilter');
...
now I want to write these with prefix ,group and resources but I have a problem when write like this :
Route::prefix('dashboard')->group(function()
{
Route::prefix('class')->group(function()
{
Route::resource('/', 'classController');
Route::get('/get-by-filter', 'classController@getByFilter');
Route::get('/get-by-search', 'classController@getBySearch');
});
Route::prefix('orders')->group(function()
{
Route::resource('/', 'OrderController');
Route::get('/get-by-filter', 'OrderController@getByFilter');
Route::get('/get-by-search', 'OrderController@getBySearch');
});
});
why return 404 when I try to access show address like this :
example.com/dashboard/orders/4
Upvotes: 2
Views: 3061
Reputation: 3284
Okay i think i got it, all you need to pass {id} in the url then dd($id) in your controller method.
Route::group(['prefix'=>'dashboard'], function()
{
Route::group(['prefix'=>'class'], function()
{
Route::resource('/', 'classController');
Route::get('/get-by-filter', 'classController@getByFilter');
Route::get('/get-by-search', 'classController@getBySearch');
});
Route::group(['prefix'=>'orders'], function()
{
Route::resource('/{id}','classController');
Route::get('/get-by-filter', 'OrderController@getByFilter');
Route::get('/get-by-search', 'OrderController@getBySearch');
});
});
I suggest you to use proper namespace and make sure your classController redirect to exact method.
Upvotes: 0
Reputation:
You need to write resource
instead of get
Route::prefix('dashboard')->group(function()
{
Route::prefix('class')->group(function()
{
Route::resource('/', 'classController');
Route::get('/get-by-filter', 'classController@getByFilter');
Route::get('/get-by-search', 'classController@getBySearch');
});
Route::prefix('orders')->group(function()
{
Route::resource('/', 'OrderController');
Route::get('/get-by-filter', 'OrderController@getByFilter');
Route::get('/get-by-search', 'OrderController@getBySearch');
});
});
Upvotes: 1
Reputation: 5582
I'm using group routing like this.
<?php
Route::group(['prefix' => 'dashboard'], function() {
Route::group(['prefix' => 'class'], function() {
Route::resource('/', 'classController');
Route::get('/get-by-filter', 'classController@getByFilter');
Route::get('/get-by-search', 'classController@getBySearch');
});
Route::group(['prefix' => 'orders'], function() {
Route::resource('/', 'OrderController');
Route::get('/get-by-filter', 'OrderController@getByFilter');
Route::get('/get-by-search', 'OrderController@getBySearch');
});
});
Try this. May be this will help you.
Upvotes: 0