Hi everyone i have a many-to-many relationship between the turnos
table and the dias
table like this:
Currently, I'm doing the CRUD of the turnos
table and for each turnos
I have to assign many dias
, I did it with the attach method.
Now the issue is in the edit
method... how am I gonna get the assigned dias
that is related to that turno
so I can pass it to the view and the user can edit it?
If someone knows it please help me, I would appreciate it very much
//Dias Model
public function turnos()
{
return $this->belongsToMany(Turno::class);
}
//Turnos Model
public function dias()
{
return $this->belongsToMany(Dia::class);
}
// Controller
public function edit(Turno $turno)
{
// $dias = ??
return Inertia::render('Turnos/Editar', [
'turno' => $turno,
'dias' => ??
]);
}
The edit view Should looks like this:
$turno->dias
to get them all.