I try to delete an item form a pivot query , and i'm not sure if i do the right method .
Here my view with some "football stades" for a structure (club)
structure can have many stades and stades have many structures
here my model Stade :
public function structures()
{
return $this->belongsToMany('App\Structure');
}
here my model Structure :
public function stades(){
return $this->belongsToMany('App\Stade');
}
My pivot table is like:
structure_id
stade_id
@foreach($club->stades as $stade)
<tr>
<th>{{$stade->lb_nom}}</th>
<th>{{$stade->adresse_stade}}</th>
<th>{{$stade->ville_stade}}</th>
<th>{{$stade->cd_post_stade}}</th>
<th>{{$stade->tel_stade}}</th>
<th>
{{ Form::open(['method' => 'DELETE', 'route' => ['club.stade.destroy', $club->id , $stade->id ]]) }}
{{ Form::submit('Delete', ['class' => 'btn btn-danger']) }}
{{ Form::close() }}
</th>
</tr>
@endforeach
I can insert a new stade to a structure without any problems
public function store(Request $request , $id){
$stade_structure = new ClubStade;
$structure = Structure::findOrFail($id);
$stade_structure->structure_id = $structure->id;
$stade_structure->stade_id = $request->input('stade_id');
$stade_structure->save();
return back()->with('status', "Un nouveau stade à été ajouté pour votre Club ! ");
}
but now i would like to detach or delete the record from the table . do i need to make a delete function ?
thanks a lot in advance
$stade->structures()->detach([1, 2, 3...])