Friday, 26 October 2018

Populating nested dropdowns using backpack for laravel

Has anyone here ever created a nested dropdown within 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 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.



from Populating nested dropdowns using backpack for laravel

No comments:

Post a Comment