Crud: Problem with Column select with getRelationModel

Created on 28 Nov 2017  路  1Comment  路  Source: Laravel-Backpack/CRUD

Bug report

I am trying to display related model attribute data, but either there's a bug or I have done something wrong. :)

What I did:

screenshot 2017-11-28 19 41 04

What I expected to happen:

wanted to display related model object attribute value

What happened:

nothing was displayed

What I've already tried to fix it:

Made temporary new custom column type
and this way data was displayed when original if ($entry->{$column['entity']}) { failed

screenshot 2017-11-28 19 40 14

Backpack, Laravel, PHP, DB version:

`
"backpack/base": "^0.8.2",
"backpack/crud": "^3.3",
"laravel/framework": "5.5.*",

php 7
`

question

Most helpful comment

@tarmo1979 if you have model relations ready. I used this way:

$this->crud->addColumn([// n-n relationship (with pivot table)
           'label' => "Types", // Table column heading
           'type' => "select_multiple",
           'name' => 'types', // the method that defines the relationship in your Model
           'entity' => 'types', // the method that defines the relationship in your Model
           'attribute' => "name", // foreign key attribute that is shown to user
           'model' => "App\Models\EventTypes", // foreign key model
        ]);

It is a 'model' => "App\Models\EventTypes" there and you can add 'pivot' => true
Also you can use model functions:

$this->crud->addColumn([ //run a function on the CRUD model and show its return value
           'name' => "count",
           'label' => "Users", // Table column heading
           'type' => "model_function",
           'function_name' => 'countEventUsers', // the method in your Model
        ]); 

>All comments

@tarmo1979 if you have model relations ready. I used this way:

$this->crud->addColumn([// n-n relationship (with pivot table)
           'label' => "Types", // Table column heading
           'type' => "select_multiple",
           'name' => 'types', // the method that defines the relationship in your Model
           'entity' => 'types', // the method that defines the relationship in your Model
           'attribute' => "name", // foreign key attribute that is shown to user
           'model' => "App\Models\EventTypes", // foreign key model
        ]);

It is a 'model' => "App\Models\EventTypes" there and you can add 'pivot' => true
Also you can use model functions:

$this->crud->addColumn([ //run a function on the CRUD model and show its return value
           'name' => "count",
           'label' => "Users", // Table column heading
           'type' => "model_function",
           'function_name' => 'countEventUsers', // the method in your Model
        ]); 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gotrecillo picture gotrecillo  路  3Comments

mikael1000 picture mikael1000  路  3Comments

sokvebolkol picture sokvebolkol  路  3Comments

mklahorst picture mklahorst  路  3Comments

sonoftheweb picture sonoftheweb  路  3Comments