skip to Main Content

I am trying to pass category id along with reorder route so I can list article based on the category. How can I overwrite reorder route like this

Route::get($segment.'/{id}/reorder', [
            'as'        => $routeName.'.reorder',
            'uses'      => $controller.'@reorder',
            'operation' => 'reorder',
        ]);

        Route::post($segment.'/{id}/reorder', [
            'as'        => $routeName.'.save.reorder',
            'uses'      => $controller.'@saveReorder',
            'operation' => 'reorder',
        ]);

2

Answers


  1. your routes should look like this,

    Route::get($segment.'/{categoryId}/{id}/reorder', [
        'as'        => $routeName.'.reorder',
        'uses'      => $controller.'@reorder',
        'operation' => 'reorder',
    ]);
    

    and Post Route,

    Route::post($segment.'/{categoryId}/{id}/reorder', [
        'as'        => $routeName.'.save.reorder',
        'uses'      => $controller.'@saveReorder',
        'operation' => 'reorder',
    ]);
    

    and then in the methods you will accept that parameters like For Example,

    public function reorder($categoryId, $id)
    {
        // your code
    }
    
    public function saveReorder(Request $request, $categoryId, $id)
    {
        // your code
    }
    
    Login or Signup to reply.
  2. To order articles in each category you have to create a nested CRUD.

    Here is a similar article to create one, which displays articles from a particular category:
    https://backpackforlaravel.com/articles/tutorials/nested-resources-in-backpack-crud

    1. Create nested CRUD.
    2. Remove ReorderOperation from ArticleCrudController.
    3. Use ReorderOperation in nested CategoryArticleCrudController.

    I hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search