yajra / laravel-datatables-editor

Laravel DataTables Editor Integration.
https://yajrabox.com/docs/laravel-datatables/editor-installation
MIT License
115 stars 14 forks source link

Using Accessor in Editor Field select ? #64

Closed Benoit75 closed 3 years ago

Benoit75 commented 3 years ago

Summary of problem or feature request

Hello, I need to concatenate 2 cols in a Editor Field Select, so i try to declare an accessor in the model and use it in html builder but
I got the Unknown column error.

Any thought how i can concatenate my two cols or to use accessor for this ?

Thank's

Model is :

class Pqrtitre extends Model { protected $fillable = [ 'nom', 'code_titre', 'annee', 'created_at', 'updated_at' ]; protected $appends = ['code_nom'];

public function getCodeNomAttribute()
{
 return $this->code_titre . " " . $this->nom; 
}

} Html Builder is ->editor( Editor::make()->fields([ Fields\Select::make('pqrtitre_id')-> tableOptions('pqrtitres', 'code_nom', 'id')-> label('Code Titre') ,

Error is Column not found: 1054 Unknown column 'code_nom' in 'field list' (SQL: select code_nom as label, id as value from pqrtitres)

Code snippet of problem

System details

Yajra Datable editor V1.24

yajra commented 3 years ago

Use modelOptions in you want to use an accessor.

->modelOptions(Pqrtitre::class, 'code_nom')

If you want some more query, you can pass a builder instead

->modelOptions(Pqrtitre::query()..., 'code_nom')
Benoit75 commented 3 years ago

Many thank's, works like a charm !

Fields\Select::make('pqrtitre_id')-> modelOptions(Pqrtitre::class, 'code_nom')-> label('Code Titre') Best Regards