Laravel Backpack Pro creating separate form in a tab of the main form

26 Views Asked by At

I have a main siteCrudController that is responsible for the all CRUD related operations for sites. However, within it I also want to create a seperate tab from which the users will be manage to manage their site locations.

I am unable to get the fields from location_sites table to be automatically populated using either

@foreach($try as $field)
            @include('crud::fields.inc.wrapper_start')
                <label for="{{ $field['name'] }}">{{ $field['label'] }}</label>
                {!! Backpack::getField($field['type'], $field) !!}
                <!-- Display all validation errors -->
                @include('crud::fields.inc.wrapper_end')
        @endforeach 

or

   @if(view()->exists('vendor.backpack.crud.form_content'))
            @include('vendor.backpack.crud.form_content', [ 'fields' => $try, 'action' => 'create' ])
        @else
            @include('crud::form_content', [ 'fields' => $try, 'action' => 'create' ])
        @endif

The former will return the error backpack class is not found and the latter will result in the page load exceeding timeout and repeatedly generate fields belonging to the siteCrudController instead

SiteCrudController
    protected function setupUpdateOperation()
    {
        CRUD::setFromDb(); // set fields from db columns.
        CRUD::addFields(static::getFieldsArrayForLocationsTab($this));
    }

    public static function getFieldsArrayForLocationsTab($self){
        // -----------------
        // SELECTS tab
        // -----------------

        $self->data['try'] =[
            [
                'name' => 'name',
                'label' => 'Name',
                'type' => 'text',
                'attributes' => [
                    // Any additional attributes can be specified here
                ]
            ]
        ];
        
        return [
            [
                'name'    => 'location',
                'label'   => 'Locations',
                'tab'     => 'Locations',
                'type'    => 'view',
                'view'      => 'sites/location_list_tab',
            ],
        ];
    }

location_list_tab.blade.php

<div>
<p>Location List Tab</p>
{{-- Create Input Fields Here --}}
<div class="alert alert-danger"></div>

<div id="locationSiteForm">
    @foreach($try as $field)
        @include('crud::fields.inc.wrapper_start')
            <label for="{{ $field['name'] }}">{{ $field['label'] }}</label>
            {!! Backpack::getField($field['type'], $field) !!}
            <!-- Display all validation errors -->
            @include('crud::fields.inc.wrapper_end')
    @endforeach
</div>

<button type="button" id="updateLocationSiteBtn" class="btn btn-primary">Save Location Site</button>
1

There are 1 best solutions below

0
Jorge On

I can not find the "getField", but maybe you want to try to access Backpack methods using "$crud", like this:

{!! $crud->getFields($field['type']) !!}

As an example, you can dd the fields:

@php(dd($crud->getFields($field['type'])))

Cheers.