Relation fromModel
custom name
#2752
-
Hello, I'd like to show combination of two columns in user-visible select name in Relation field-type. As it's easy for TD and Sight using My case is following: TD example: TD::make('workplace', 'Workplace')
->render(function ($model) {
return ($model->workplace->department->name . ' - ' . $model->workplace->name);
}), Any ideas? :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can add a calculated attribute to your model, for example class Workplace extends Model
{
/**
* @return string
*/
public function getFullNameAttribute(): string
{
return $model->department->name . ' - ' . $model->name;
}
} Then use the Relation::make('workplace.')
->fromModel(Workplace::class, 'name')
->displayAppend('fullName')
->multiple()
->title('Select workplace'); |
Beta Was this translation helpful? Give feedback.
You can add a calculated attribute to your model, for example
Then use the
displayAppend
method to specify which calculated field to use for display: