Search code examples
laravelurl-routinglaravel-backpack

creating a related items list


I have designed my crud with backpack 4.0. I have a list of items, called "accidents", and a list of related "events". I have created a custom button for my accidents list, that points to, say "accident/#accident_id/event". This should bring me to the event list related to my accident id. I did it successfully with backpack < 4. Now I need to make it on a fresh new project with backpack4, but I get some problem. This is my route configuration for the specific called list view:

Route::group(
   ['prefix' => 'accident/{accident_id}',
    'namespace'  => 'App\Http\Controllers\Admin',
   ], function() {
     Route::crud('event', 'AccidentEventCrudController');
});

And the error I get is a 404 "page not found". I have generated the crud for the "accidents", and the one for the "events", and they work. I have a AccidentEventCrudController, with the following setup function:

    public function setup() {
    // parent::setup();

    // get the accident_id parameter
    $accident_id = \Route::current()->parameter('accident_id');

    // set a different route for the admin panel buttons
    $this->crud->setRoute('admin/accident/' .$accident_id . '/event');

    // show only that Accident's Events
    $this->crud->addClause('where', 'accident_id', '=', $accident_id );
}

What am I doing wrong? Thanks in advance.


Solution

  • So because this got solved in a comment, I now post this here:

    You've been missing the admin prefix in 'prefix' before 'accident/', causing it to work more with accident/{id}/event rather than admin/accident/{id}/event