2

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

3 Answers 3

1

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');
         });

});
Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry, that was my wrong in type. I do this but It dose not work yet!
0

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.

4 Comments

thank you for your response. I try this way but it dose not work yet!
and also run this command on console php artisan route:list then this will show you all the routes listing.
when I run this: php artisan route:list , I can see there is a route like this : /dashboard/orders/{}. but when I type in url get 404 err.
Firstly clear your laravel.log file and run again hit orders url and then check laravel.log file. error will be logged there.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.