Including list view of relationship entity on update page

后端 未结 2 903
青春惊慌失措
青春惊慌失措 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:42

    As @tabacitu mentioned, Backpack doesn't currently have an built in solution for this. That said, this could maybe work for you:

    This would allow you to use all functionality of the nested list view including interacting with the entities without conflicting at all with the parent

    Step 1, Build your normal CRUDs

    • Build out two normal CRUDs, one for Publishers, and one for Volumes

    Step 2, Make a frameless layout

    • copy vendor/backpack/base/layout.blade.php
    • name it frameless-layout.blade.php
    • remove @include('backpack::inc.main_header') and @include('backpack::inc.sidebar')

    Step 3, Make a custom list view

    • copy vendor/backpack/crud/list.blade.php
    • name it sub-list.blade.php
    • change the top line to @extends('backpack::frameless-layout')

    Step 4, Make a custom field

    • Create a custom form field that contains an iFrame
    • Inside your custom field template, have it set the url of the iFrame to the "list" url of the related resource
    • You'd also need to utilize List Filters and a method for setting them dynamically so that the sub-list shows only the records related to the parent

    Step 5, Configure and use the field

    • In your crud controllers, use the addField to add the the configuration for the new field and its related model
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题