Column relationships problem

Hey !

In a relation manager resource, i have this code :
public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('enseignants')
                    ->badge(),
            ])


with just "Tables\Columns\TextColumn::make('enseignants')", i have my badges filled with json, like "{"id":15,"civilite_id":2,"prenom":"Audrey","nom" ...." .
Usually i have to add the field, like "Tables\Columns\TextColumn::make('enseignants.prenom')" to display only "prenom" in the badge. but when i add it, i have a "Call to a member function enseignants() on null" error.

The models is :

class MatiereSession extends Pivot
{
    use HasFactory;

    protected $table = 'matiere_session';

    public function matiere(): BelongsTo
    {
        return $this->belongsTo(Matiere::class);
    }

    public function session(): BelongsTo
    {
        return $this->belongsTo(Session::class);
    }

    public function enseignants()
    {
        return $this->matiere->enseignants()->wherePivot('session_id', $this->session->id);

    }
`

I dont know what to do to make it work :/
Was this page helpful?