F
Filament10mo ago
Nazgul

Repeater datas not showing on edit

Hey, i'm trying to setup a repeater inside a form (Patient), when i save the form, all datas are created in database even the relationship datas. But when i try to edit the patient, the reapeater datas are not showing. What am i doing wrong? Inside Patient model :
public function patientDatas(): HasMany
{
return $this->hasMany(PatientData::class);
}
public function patientDatas(): HasMany
{
return $this->hasMany(PatientData::class);
}
Inside PatientData model:
public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
Inside PatientResource:
Fieldset::make()
->schema([
Repeater::make('patientDatas')
->relationship()
Fieldset::make()
->schema([
Repeater::make('patientDatas')
->relationship()
18 Replies
Troner
Troner10mo ago
@Sam i have the same problem, please tell me when you find a solution, i will do the same
Nazgul
NazgulOP10mo ago
@Troner for know i've looked everywhere and cant find any solution 😦 thats why im posting here
Troner
Troner10mo ago
@Sam i am looking for 1 hour straight now, haven't given up yet @Sam i fixed it for my case. i will create a minified code version to paste it here
Nazgul
NazgulOP10mo ago
oh nice! lets see it
Troner
Troner10mo ago
i need some minutes
`// EnergyResource
->schema([
Forms\Components\Repeater::make('energyNutritionalValues')
->relationship()
->schema([
Forms\Components\Select::make('nutritional_value_id')
->label('Nährwert')
->relationship('nutritionalValues', 'name')
->searchable()
->createOptionForm([
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('unit'),
])
->live(onBlur: true),
Forms\Components\TextInput::make('amount')
->disabled(fn (Get $get) => $get('nutritional_value_id') === null)
->suffix(function (Get $get) {
if ($get('nutritional_value_id') === null) {
return 'Einheit';
} else {
return NutritionalValue::where('id', $get('nutritional_value_id'))->first()->unit ?? '';
}
}),
]),
])

// Energy Model

class Energy extends Model
{
public function energyNutritionalValues()
{
return $this->hasMany(EnergyNutritionalValue::class);
}
}

// EnergyNutritionalValue Model

class EnergyNutritionalValue extends Pivot
{
protected $table = 'energy_nutritional_values';

public function energy()
{
return $this->belongsTo(Energy::class);
}

public function nutritionalValues()
{
return $this->belongsTo(NutritionalValue::class, 'nutritional_value_id', 'id');
}
}

// NutritionalValue Model

class NutritionalValue extends Model
{
protected $table = 'nutritional_values';

public function energies()
{
return $this->belongsToMany(Energy::class, 'energy_nutritional_values', 'nutritional_value_id', 'energy_id');
}
}
`// EnergyResource
->schema([
Forms\Components\Repeater::make('energyNutritionalValues')
->relationship()
->schema([
Forms\Components\Select::make('nutritional_value_id')
->label('Nährwert')
->relationship('nutritionalValues', 'name')
->searchable()
->createOptionForm([
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('unit'),
])
->live(onBlur: true),
Forms\Components\TextInput::make('amount')
->disabled(fn (Get $get) => $get('nutritional_value_id') === null)
->suffix(function (Get $get) {
if ($get('nutritional_value_id') === null) {
return 'Einheit';
} else {
return NutritionalValue::where('id', $get('nutritional_value_id'))->first()->unit ?? '';
}
}),
]),
])

// Energy Model

class Energy extends Model
{
public function energyNutritionalValues()
{
return $this->hasMany(EnergyNutritionalValue::class);
}
}

// EnergyNutritionalValue Model

class EnergyNutritionalValue extends Pivot
{
protected $table = 'energy_nutritional_values';

public function energy()
{
return $this->belongsTo(Energy::class);
}

public function nutritionalValues()
{
return $this->belongsTo(NutritionalValue::class, 'nutritional_value_id', 'id');
}
}

// NutritionalValue Model

class NutritionalValue extends Model
{
protected $table = 'nutritional_values';

public function energies()
{
return $this->belongsToMany(Energy::class, 'energy_nutritional_values', 'nutritional_value_id', 'energy_id');
}
}
Nazgul
NazgulOP10mo ago
mmm what was the fix? i basically have the same models definitions and same form in my resource
Troner
Troner10mo ago
i didnt know what exactly the cause was i had many diffrent errors along the way do you have all needed columns in protected $fillable?
Nazgul
NazgulOP10mo ago
i have every column in fillable yeah
Troner
Troner10mo ago
or maybe you have a another Select::make Entry for example that has a name of a another relation, then it doesnt work, that was also an issue for me
Nazgul
NazgulOP10mo ago
i dont have select in my form
Troner
Troner10mo ago
can i see your code?
Nazgul
NazgulOP10mo ago
of my resource?
Fieldset::make()
->schema([
Repeater::make('patientDatas')
->relationship()
->schema([
Fieldset::make('Anamnesis')
->schema([
Select::make('version')
->label('Version:')
->inlineLabel()
->searchable()
->options([
1 => 'v1',
2 => 'v2',
3 => 'v3',
4 => 'v4',
]),
Fieldset::make()
->schema([
Repeater::make('patientDatas')
->relationship()
->schema([
Fieldset::make('Anamnesis')
->schema([
Select::make('version')
->label('Version:')
->inlineLabel()
->searchable()
->options([
1 => 'v1',
2 => 'v2',
3 => 'v3',
4 => 'v4',
]),
Troner
Troner10mo ago
Like my code with Resource, Models and Relations
Nazgul
NazgulOP10mo ago
//Patient model

protected $fillable = [
'name',
'surname',
'set',
'fiscal_code',
'patient_initial',
'birthdate',
'postal_code',
'address',
'city',
'province',
'nationality',
'phone_number',
'weight',
'size',
'start_date',
'end_date',
'diagnostic_date',
'familial_wart_antecedent',
'familial_wart_antecedent_description',
'personal_wart_antecedent',
'personal_wart_antecedent_description',
'diabetes_mellitus',
'chronic_illness',
'immunosuppression',
'smoking',
'vascular_illness',
'arthritis',
'insulin',
'anti_hypertensive',
'anticoagulant',
'allergy',
'allergy_description',
];

public function patientDatas(): HasMany
{
return $this->hasMany(PatientData::class);
}
//Patient model

protected $fillable = [
'name',
'surname',
'set',
'fiscal_code',
'patient_initial',
'birthdate',
'postal_code',
'address',
'city',
'province',
'nationality',
'phone_number',
'weight',
'size',
'start_date',
'end_date',
'diagnostic_date',
'familial_wart_antecedent',
'familial_wart_antecedent_description',
'personal_wart_antecedent',
'personal_wart_antecedent_description',
'diabetes_mellitus',
'chronic_illness',
'immunosuppression',
'smoking',
'vascular_illness',
'arthritis',
'insulin',
'anti_hypertensive',
'anticoagulant',
'allergy',
'allergy_description',
];

public function patientDatas(): HasMany
{
return $this->hasMany(PatientData::class);
}
`
//PatientData model

protected $fillable = [
'version',
'date',
'wart_number',
'localisation',
'complication',
'habitual_shoe',
'nrs_score',
'treatment_pain_score',
'week_pain_score',
'scalpel_deslamination',
'five_second_treatment',
'felt_application',
'progression_proof',
'patient_id'
];



public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
//PatientData model

protected $fillable = [
'version',
'date',
'wart_number',
'localisation',
'complication',
'habitual_shoe',
'nrs_score',
'treatment_pain_score',
'week_pain_score',
'scalpel_deslamination',
'five_second_treatment',
'felt_application',
'progression_proof',
'patient_id'
];



public function patient(): BelongsTo
{
return $this->belongsTo(Patient::class);
}
and you have a snippet of the Repeater code higher
Troner
Troner10mo ago
Hmmm, so you dont get any erros right? Just the repeater isn't rendered on edit page? Do you get an error if you create a new entry? for me i got an error when creating new entry but it stored in in the database anyway
Nazgul
NazgulOP10mo ago
I dont get any errors, on create its creating the datas in database, but when i edit i see no datas in the repeater still havent figured it, damn it its crazy
Patrick
Patrick10mo ago
i had this too few weeks back, let me find the answer oh no sorry that was a different issue with repeaters
Nazgul
NazgulOP10mo ago
had some hope for a moment haha
Want results from more Discord servers?
Add your server