Hy ...I'm new to Laracast. I have a problem and I try to explain.
I have three tables
- pellets
- specie
- specie_pellet (The specie are the trees)
The tree_pellet is a pivot table with fields
- pellet_id
- specie_id
- percentage
I have setting my models for the relations so:
Pellet
public function specie()
{
return $this->belongsToMany(Specie::class)->withPivot('percentuale');
}
Specie
public function pellets()
{
return $this->belongsToMany(Pellet::class)->withPivot('percentuale');
}
I have also create a Form for Update the tree_pellet so:
{!! Form::model($pellet, ['method' => 'PUT', 'route' => ['composizione.update', $pellet->id]]) !!}
Specie
Percentuale
Azione
@foreach($pellet->specie as $specie)
{!! Form::select('specie[]', $listaSpecie, $specie->id, ['class' => 'form-control']) !!}
Elimina
@endforeach
{!! Form::submit('Aggiorna Composizione', ['class' => 'btn btn-success']) !!}
{!! Form::close() !!}
A pellet can have multiple configurations:
- 5 - 1 - 50 (5 is the pellet_id - 1 is the specie_id - 50 is the percentage)
- 5 - 7 - 50 (5 is the pellet_id - 7 is the specie_id - 50 is the percentage)
- (example: a bio pellet is make with 50% of silver fir and 50% red fir)
But when I try to update i receive this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `pellet_specie` (`0`, `pellet_id`, `specie_id`, `1`) values (1, 5, 0, 7))
Someone can try to help me please?