in Database Ich habe eine Tabelle von Produkt- und Komponenten
und ich habe eine Tabelle für viele zu viele Beziehung, die component_product es ein Attribute (product_id, component_id haben, ist, Menge)Laravel Illegal Offset-Typ auf vielen zu vielen mit extra Spalte
in Modell Artikel
class Product extends Model
{
protected $fillable = [
'name','price','user_id','is_avilable','description'
];
public function components()
{
return $this->belongsToMany('App\Component')
->withPivot('quantity');
}
}
in Ansicht
{!! Form::select('component_id[]',$components,null !!}
{!! Form::select('component_id[]',$components,null !!}
{!! Form::number('quantity[]',null ]) !!}
{!! Form::number('quantity[]',null ]) !!}
in Controller
public function store(Request $request)
{
$product= Product::create($request->all());
$product->components()->sync($request->component_id => ['quantity'=> $request->quantity ]);
}
Es gibt mir einen Fehler von Illegal versetzem
Hinweis: wenn sterben Dump $ request-> Menge oder Anfrage- $> component_id wird es das Array erhalten richtig