Many to many relationships in the model
public function drycleanings()
{
return $this->belongsToMany('App\drycleaning')
->withPivot('$cart_id','drycleaning_id','q_drycleaning_id');
}
and
public function carts()
{
return $this->belongsToMany('App\cart')
->withPivot('$cart_id','drycleaning_id','q_drycleaning_id');
}
In the controller I am using
$cart->drycleanings()->attach($request->drycleaning_id,[$request->q_drycleaning_id]);
if gives me an error
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list'
Result of dd($request->all());
"drycleaning_id" => array:2 [▼
0 => "3"
1 => "4"
]
"q_drycleaning_id" => array:58 [▼
0 => "2"
1 => "2"
2 => null
3 => null
4 => null
5 => null
6 => null
7 => null
8 => null
9 => null
10 => null
]
Is there any way I can only pass non-null values? or any other solution to save both into association table?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2qZUp01
via IFTTT
Aucun commentaire:
Enregistrer un commentaire