mardi 12 septembre 2017

Laravel Backpack:

I'm using Laravel Backpack (CRUD) manager.

I have two tables that are imported from an outside database and the structure can't change.

I'm trying to display two columns with data from two separate tables.

Table 1: Item Table 2: ItemDynamic

Table 1: Item.ID Link to Table 1 from Table 1-> ItemDynamic.ItemID

The CRUD AJAX Columns should look like this: Item.ID | ItemDynamic.ItemID

How is this possible?

ItemDynamic Model:

public function Item()
    {
        return $this->hasOne('App\Item', 'id', 'itemid');
    }

ItemDynamic Controller

$this->crud->setColumns([
            [
                'name' => 'ItemID',
                'label' => 'UPC',
                'type' => 'ItemID',
                'function_name' => 'ItemID',
            ],
            [
                // 1-n relationship
                'label' => "id", // Table column heading
                'type' => "select",
                'name' => 'id', // the column that contains the ID of that connected entity;
                'entity' => 'Item', // the method that defines the relationship in your Model
                'attribute' => "name", // foreign key attribute that is shown to user
                'model' => "App\Models\ItemDynamic", // foreign key model
             ],
        ]);

ItemID appears correctly but when I add the second column (id) I get an AJAX error. How can I get this to appear?

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire