Skip to content

Relation supports laravel accessors #1517

Answered by tabuna
dhb52 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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('

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dhb52
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants