2
I have this model
public function exercicio()
{
return $this->belongsToMany(Exercicio::class);
}
and
public function treino()
{
return $this->belongsToMany(Treino::class);
}
My Controller
public function salvarTreino(Request $request)
{
}
How do I save an exercise list in training?
at the moment it’s like this
public function salvarTreino(Request $request)
{
$treino = new Treino();
$treino->nome = $request->nome;
$treino->save();
$treino->exercicio()->attach([1]);
return response()->json("", 201);
}
however i am manually passing the exercise id, I want the user can choose
Your question is easy to answer but, I need to see the layout of the tables, the model in its entirety and your view to give a reliable and faithful answer to what you have! Just remembering that here is Stackoverflow in Portuguese!
– novic
I didn’t see it when I posted :/ so I won’t have the view, this controller will return a json.
– fellipe rocha
Have a copy of
Json
and in it comes the code of training?– novic
In save function I want the user to name the training and choose an exercise q has been previously registered
– fellipe rocha
I understand, are you sending this data in what way? or is that your doubt?
– novic