Hello, how could I save this request in a table called Cat_favoritas
which the arrangement of categories comes from a checkbox
array:3 [▼
"_token" => "mqBPCysHUomaBF52LUMisDvI4Ptx5ygYQL1MQOj3"
"categoria" => array:3 [▼
0 => "2"
1 => "3"
2 => "1"
]
"user_id" => 6
]
It turns out that according to the checkbox that the user checks, the controller receives them
<label class="selectgroup-item">
<input type="checkbox" name="categorias[]" value="{{$categoria->id}}" class="selectgroup-input" checked>
<span class="selectgroup-button">{{$categoria->nombre}}</span>
</label>
but I have 3 tables
| Users | Categorias | Cat_favoritas |
First in the view it shows all the available categories, after having selected just I am trying to save it in Cat_favoritas
I've been trying using SYNC but I do not know how to translate it
My models and their relationships
| user |
public function Cat_Favorita()
{
return $this->hasMany(Cat_favorita::class);
}
Category Model
public function Cat_favorita()
{
return $this->HasMany(Cat_favorita::class);
}
And finally the model Cat_favorita
public function Categoria()
{
return $this->belongsToMany(Categoria::class,'categoria_id');
}
public function User()
{
return $this->belongsToMany(User::class,'user_id');
}
No estoy seguro que esto este bie.