Filament Repeater Not Passing Foreign Key (make_id) - SQL Error 1364
I'm using a Filament Repeater to add vehicle compatibility records in my Laravel app. The make_id field is a foreign key, but when saving, I get this error:
SQLSTATE[HY000]: General error: 1364 Field 'make_id' doesn't have a default value (Connection: mysql, SQL: insert into
part_compatibility
(part_id
, updated_at
, created_at
) values (29, 2025-02-04 08:42:29, 2025-02-04 08:42:29))
CompatibilitiesRelationManager file attached
Part Model:
class Part extends Model
{
protected $fillable = [
'supplier_id',
'part_name',
'part_number',
'brand',
'description',
'category',
'unit_of_measurement',
'stock_level',
'quantity_per_unit',
'purchase_price',
'selling_price',
'remarks',
];
public function supplier()
{
return $this->belongsTo(Supplier::class, 'supplier_id');
}
public function compatibilities()
{
return $this->hasMany(PartCompatibility::class);
}
}
PartCompatibility Model:
class PartCompatibility extends Model
{
protected $table = 'part_compatibility';
protected $fillable = [
'part_id',
'make_id',
'model_id',
'years',
];
protected $casts = [
'model_id' => 'array', // Cast model_id to an array
'years' => 'array', // Cast years to an array
];
public function part()
{
return $this->belongsTo(Part::class, 'part_id');
}
public function make()
{
return $this->belongsTo(VehicleMake::class, 'make_id');
}
public function model()
{
return $this->belongsTo(VehicleModel::class, 'model_id');
}
}
4 Replies
I think the issue is, that you choose
relationship()
for make_id
so it doesn't return that value, but tries to save to the relationship directly@Dennis Koch Thank you for your reply
I tried that as well like this
Forms\Components\Select::make('make_id')
->label('Vehicle Make')
->preload()
->options(\App\Models\VehicleMake::pluck('make_name', 'id'))
->required()
->searchable()
->reactive(),
but still the same error. It works fine without Repeaters, I dont know what is that i'm doing wrong with repeaters.
That’s weird. I’d expect that to work. What do you mean by „works fine without repeaters“? How did you test? Plain Laravel calls?
without repeaters meaning, with select & textinput fields. like this and it is working fine.