I hope you are fine. I have a problem with a pivot table in laravel 5.1 I want it that several products are inserted into this table , which have made relations with two more tables . The problem is that inserts well ids products, but the extra fields such as quantity and price would not add them all , that is , I only adds a value of one product, do not know if I explained well . Of all forms attached photos of models , drivers and user view with the database . Is there something missing I do? Please if you can help me . Beforehand thank you very much!! PD: Sorry my english. I´m from latin america and I don´t speak english very well.
http://ift.tt/26vEZiO http://ift.tt/1NUXtxZ
Bill model
class Bill extends Model
{
protected $table = 'bills'; protected $fillable = ['date_at'];
public function products()
{
return $this->belongsToMany('App\Product','bill_product','product_id', 'bill_id','dquantity','dprice')->withTimestamps();
}
}
Product Model
class Product extends Model
{
protected $table = 'products';
protected $fillable = ['name', 'price','stock'];
public function bills() { return $this->belongsToMany('App\Bill','bill_product','bill_id', 'product_id','dquantity','dprice')->withTimestamps(); } }
Controller
public function store(Request $request)
{
$fac = Bill::create($request->all());
//Obtener ids de lineas de productos
$productIds = $request->input('product_id');
$cant= $request->input('dquantity');
$prec=$request->input('dprice');
$fac->products()->attach($productIds , ['dprice' => $prec,'dquantity' => $cant]);
}
View
</td>
<td>
{!!Form::select('product_id[]',$produ,null,['class'=>'form-control'])!!}
</td>
<td width="20%">
{!!Form::text('dquantity', null,['class'=>'form-control','id'=>'cantidad'])!!}
</td>
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/26vEWUq
via IFTTT
Aucun commentaire:
Enregistrer un commentaire