Crud: Column selection

Created on 23 Jun 2017  路  5Comments  路  Source: Laravel-Backpack/CRUD

When I use the model_function column type (with ajax table enabled), and try to access a field from the model inside a model function, it returns null. I believe it's because it's because of this line.
Because when column type model_function selected, it doesn't add column name to required columns.

[
    'name'          => 'expires', //ignored
    'type'          => 'model_function',
    'function_name' => 'isExpiredText',
    'label'         => trans('ctkm.credit.expired'),
],

// model

public function isExpiredText()
{
    dd($this->expires == null); //true
    ...
}

OR, for my custom column type, I don't need any column. For example, when I want to use attribute of models relation (HasOne).

 [
    'name'      => 'id', // 'name' is required
    'type'      => 'textRelation',
    'entity'    => 'operation', //relation name
    'attribute' => 'comment', //relations column
    'label'     => trans('ctkm.credit.comment'),
],

//model
public function operation()
{
   return $this->hasOne(Operation::class);
}

// view
<td>
    @isset($entry->{$column['entity']})
        @isset($entry->{$column['entity']}->{$column['attribute']})
            {{$entry->{$column['entity']}->{$column['attribute']} }}
        @endisset
    @endisset
</td>

TL;DR: There is no way to ask backpack to select or not to select (ignore) columns when querying items.

I'm sorry if it's not clear, I don't know how else to word it :)

Bug

All 5 comments

Seems like it. Hope that will be merged soon :).

@tabacitu is there a way to ask crud to select a field that is not used in any columns?
For example, say I have custom column view, and I want to use multiple fields from the row to render that view. The fields that I want to use will be always null because crud doesn't select them.

I wonder why nobody encountered this issue.

@tabacitu I fixed it myself.
Will you accept a fix PR like in this commit? or will it be really fixed by #710?

Hi @alashow - thanks for the PR, in the meantime it's been fixed on the upgrade branch, when I rewrote the whole AjaxDataTables implementation. So you shouldn't have that issue anymore, once we launch 3.3 later this week. Thanks, cheers!

Was this page helpful?
0 / 5 - 0 ratings