concatenate fields CRUD #564
-
I need to understand on thing.. public function user()
{
return $this->belongsTo('App\Models\User');
} In RequestCrudController if use Second question: In user table i've fields first_name and second_name and in my RequestCrudController i'd like to use something like this: I've tried to create an accessor like this: public function getFullNameAttribute()
{
return $this->first_name . ' ' . $this->last_name;
} But i don't know how to use it in CRUD ! Searching on web i've found this old (2017) issue: Laravel-Backpack/CRUD#402 The solutions there are still valid or now that we have Laravel 10.x and BackPack 5.x or 6.x there are better solutions ? Thanks for help |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi @blondie63 ,
Backpack tries to
You can see exactly how If it's not correct for your model you can do something like this on your User model and then Backpack won't try to guess it any more: public $identifiableAttribute = "name";
You add CRUD columns for accessors, no problem, just do public $appends = ['full_name']; Hope it helps. |
Beta Was this translation helpful? Give feedback.
-
Hi @tabacitu , i need a little more help.. :) Is it possible to create something on Models to have this double jump ? :) |
Beta Was this translation helpful? Give feedback.
-
@tabacitu relations you can see on my screenshot was created by DevTools fields name ? for example on my RequestFlow model i've this: and
CRUD::column('statusStart') works fine, using function name as column name |
Beta Was this translation helpful? Give feedback.
Hi @blondie63 ,
Backpack tries to
You can see exactly how
identifiableAttribute
works here: https://github.com/Laravel-Backpack/CRUD/blob/main/src/app/Models/Traits/HasIdentifiableAttribute.phpIf it's not correct for your model you can do something like this on your User…