53

Has anyone here ever created a nested dropdown within the backpack's cruds?

I've got this crud controller which handles the 'Campaign' model -

$this->crud->addField([
        'name' => 'industry_id',
        'entity' => 'industry',
        'type' => 'select2',
        'attribute' => 'name',
        'label' => "Industry",
    ]);
    $this->crud->addField([
        'name' => 'country_id',
        'entity' => 'country',
        'type' => 'select2',
        'attribute' => 'country_name',
        'label' => "Country",
    ]);

    $this->crud->addField([
        'name' => 'website_id',
        'entity' => 'website',
        'type' => 'select2',
        'attribute' => 'name',
        'label' => "Website",
    ]);
    $this->crud->addField([
        'name' => 'campaign_type_id',
        'entity' => 'campaign_type',
        'type' => 'select2',
        'attribute' => 'name',
        'label' => "Campaign Type",
    ]);

    $this->crud->addField([
        'name' => 'site_page_id',
        'entity' => 'site_page',
        'type' => 'select2',
        'attribute' => 'name',
        'label' => "Site Page",
    ]);

The 'website' entity depends on the industry field, and the 'site_page_id' depends on the cross between the 'website' entity and the 'campaign_type' entity.

When I'm creating a new campaign, I'm willing the dropdowns to be filled up dynamically according to the selected value of the dropdown above them.

I tried adding a method to the campaign's model as suggested in this pull and call it within the crud field's but it didn't work.

The only solution I can think of now is creating a custom create.blade.php file and call it with $this->crud->setCreateView('vendor.backpack.base.new_create'); from campaign's model setup() method.

4
  • 1
    Gonras, that PR should work, I’ve tried it many times. The only thing it doesn’t do is clear subsequent inputs. Commented Nov 1, 2018 at 7:07
  • Take note you’d need to use select2_from_ajax, not select2. Commented Nov 1, 2018 at 7:08
  • Rather than create a new create.blade.php file you could create a custom files type that includes all 3 fields you need - that should be easier. Commented Nov 1, 2018 at 7:08
  • backpackforlaravel.com/docs/3.4/… Commented Nov 1, 2018 at 7:09

1 Answer 1

1

You can use $this->crud->with(); or $this->crud->with(['website', 'site_page']); It will get all the duplicate data in the relationships.

Let me know if this helped

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

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.