FilamentF
Filament3y ago
N1XN

RelationManager attempts to lazy load relations

I have created an Attribute to display a range, which combines min and max BelongsTo Relations, but I get the enabled strictMode error thrown.

Attempted to lazy load [minDose] on model [App\Models\PatientMedication] but lazy loading is disabled.

Is there a way how I can manually load the needed relations via TextColumn API?

// MedicationDoseRelationManager
// ...
TextColumn::make('medicationDoseRange')
    ->label('Dose'),
// ...


class PatientMedication extends Model
{
    public function minDose(): BelongsTo
    {
        return $this->belongsTo(Dose::class, 'min_dose_id');
    }

    public function maxDose(): BelongsTo
    {
        return $this->belongsTo(Dose::class, 'max_dose_id');
    }

    protected function medicationDoseRange(): Attribute
    {
        return Attribute::make(
            get: function () {
                $consolidatedValue = $this->minDose->name === $this->maxDose->name; // Error get trown

                return $consolidatedValue
                    ? $this->minDose->name
                    : $this->minDose->name.' - '.$this->maxDose->name;
            }
        );
    }
}
Was this page helpful?