I have three table and i'm in a many to many relationship.
Table "semaine"
id | name |
Table "bitheme"
id | namebitheme
Table "bitheme_semaine". In it i add a new "statut" columns
bitheme_id | semaine_id | statut
In my case I can have a status of 1 or 2 if the relationship exists (in database it"s 1 by defaut on this field).
In my edit form i have to checkbox :
<input type="checkbox" name="bithemes[]" value=""> </input>
<input type="checkbox" name="statut[]" value=""> </input>
I synchronize my table as well :
$semaine->update($request->all());
$semaine->bithemes()->sync($request->input('bithemes', []));
But i also want to synchronize the status if it is checked. So I added in the relationship of my Semaine model :
public function bithemes()
{
return $this->belongsToMany(Bitheme::class)->withPivot('statut');
}
and i try to test synchronize with :
$semaine->bithemes()->sync($request->input('bithemes', []), ['statut' => 2]);
But the statut is never synchronized.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30nL3vQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire