MorphToSelect::make('productable')
->types([
MorphToSelect\Type::make(Course::class)
->titleAttribute('id') <-- Here I want to display a column from the related table, I want to display the course_title in the primary language.
->getOptionLabelUsing(function (Course $record): string {
return $record->translations()
->where('locale_id', $record->primary_locale_id)
->first()?->course_title ?? 'Untitled Course';
})
->getSearchResultsUsing(function (string $search): Builder {
return Course::whereHas('translations', function ($query) use ($search) {
$query->where('course_title', 'like', "%{$search}%");
});
}),
])
->native(false)
->required(),
MorphToSelect::make('productable')
->types([
MorphToSelect\Type::make(Course::class)
->titleAttribute('id') <-- Here I want to display a column from the related table, I want to display the course_title in the primary language.
->getOptionLabelUsing(function (Course $record): string {
return $record->translations()
->where('locale_id', $record->primary_locale_id)
->first()?->course_title ?? 'Untitled Course';
})
->getSearchResultsUsing(function (string $search): Builder {
return Course::whereHas('translations', function ($query) use ($search) {
$query->where('course_title', 'like', "%{$search}%");
});
}),
])
->native(false)
->required(),