Including list view of relationship entity on update page

后端 未结 2 923
青春惊慌失措
青春惊慌失措 2021-01-07 17:05

I am trying to extend an update view to include a list view of some related items below the edit form.

I have two models, Publishers and Volumes, which have a many t

2条回答
  •  渐次进展
    2021-01-07 17:46

    Indeed, there's no standard functionality to do that in Backpack. It's a pretty unusual way to do things. But it's not too difficult to achieve it.

    If there aren't too many Vendors for one Publisher (as I expect it's the case here), I would keep it simple and NOT try to include the entire Backpack list view (with ajax, buttons, filters, etc) on top of the form. I would add a standard HTML table with the entries (and optionally buttons to Edit Vendor with target=_blank).

    Here's how I would go about it:

    1. In the Publisher CRUD, I would use a custom view for the Edit operation; you can do that using $this->crud->setEditView('edit_publisher_with_vendors') in your setup() method;

    2. In that custom edit view (edit_publisher_with_vendors.blade.php in my example), I would copy-paste everything inside the edit.blade.php view that Backpack/CRUD is using, and add a table with the Vendors on top of the Edit form; notice you have the current entry as $entry in this view; since there's a relationship on the model, you would be able to check if it has vendors using $entry->vendors()->count(), and get the vendors using $entry->vendors.

    Hope it helps.

提交回复
热议问题