Is your max_value in your $fillables array on your model?
eloquent update doesn't seem to happen
Hi all, I just ran into a really weird problem: not all Eloquent model updates seem to happen. So far, I have this happen on only one model, but I can't see what I am doing wrong. Some tinker code below.
EDIT: this is laravel 10.10
First: I update the min_value field using update.
No problem there: it is set to the value I provide
> $sc->update(['min_value'=>17])
= true
> $sc->refresh()
= App\Models\SensorChannel {#6831
id: "99d4fd6d-5851-43d2-a9b5-062bccd02243",
min_value: 17,
max_value: 14,
crit_value: 93,
sensor_id: "99d4fd6d-53b9-4791-b1a7-a28783c0347a",
sensor_type_id: 5,
created_at: "2023-08-07 09:30:39",
updated_at: "2023-08-07 09:31:45",
}
Then the max_value...
Hm this is weird. mysql confirms that no update has happened
> $sc->update(['max_value'=>15])
= true
> $sc->refresh()
= App\Models\SensorChannel {#6831
id: "99d4fd6d-5851-43d2-a9b5-062bccd02243",
min_value: 19,
max_value: 14,
crit_value: 93,
sensor_id: "99d4fd6d-53b9-4791-b1a7-a28783c0347a",
sensor_type_id: 5,
created_at: "2023-08-07 09:30:39",
updated_at: "2023-08-07 09:32:01",
}
However, if I set the field, then save, the update does happen
> $sc->max_value=10
= 10
> $sc->save()
= true
> $sc->refresh()
= App\Models\SensorChannel {#6831
id: "99d4fd6d-5851-43d2-a9b5-062bccd02243",
min_value: 19,
max_value: 10,
crit_value: 93,
sensor_id: "99d4fd6d-53b9-4791-b1a7-a28783c0347a",
sensor_type_id: 5,
created_at: "2023-08-07 09:30:39",
updated_at: "2023-08-07 09:39:07",
}
Any ideas? please?
@D. Eikelboom thank you for your swift response. Yes it is: this is the $fillables on the SensorChannel model :
protected $fillable = [
'crit_value'.
'max_value',
'min_value',
'sensor_id',
'sensor_type_id',
];
This is really too dumb. My apologies for wasting your time and energy on this. The error is mine entirely:
ZOOM IN: 'crit_value'<dot> instead of <comma>. The exact effect of this was that I'd created a field 'crit_valuemax_value' which of course never got filled.
The tinker values come from the database, which gives the correct field names. Thank the gods of step-debugging for their hard work.
Please or to participate in this conversation.