-
Relation::make('post.author')
->title('Author')
->fromModel(User::class, 'name')
->required(), It's better idea to support laravel Accessors public function getDisplayAttribute(): string
{
return $this->name . ' (' . $this->email . ')';
} Relation::make('post.author')
->title('Author')
->fromModel(User::class, 'display')
->required(), now
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @dhb52, this works a little differently. Here's an excerpt from the documentation: Selection options can work with calculated fields, but only to display the result, the search will occur only on one column in the database. To do this, use the namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* @return string
*/
public function getFullAttribute(): string
{
return $this->attributes['name'] . ' (' . $this->attributes['email'] . ')';
}
} To indicate the displayed field you must: Relation::make('users.')
->fromModel(User::class, 'name')
->displayAppend('full')
->multiple()
->title('Select users'); |
Beta Was this translation helpful? Give feedback.
-
Thanks for solution, a subtle correctness for whom may check out this later. Relation::make('post.author') # better refactor column name to `author_id`
->fromModel(User::class, 'name')
->displayAppend('full')
->title('Select users'); |
Beta Was this translation helpful? Give feedback.
Hey @dhb52, this works a little differently. Here's an excerpt from the documentation:
Selection options can work with calculated fields, but only to display the result, the search will occur only on one column in the database. To do this, use the
displayAppend
method.To indicate the displayed field you must: