mercredi 21 mars 2018

Deleting an item by a hasthrough relationship

I was recomended to use a has though relationship to access all of a users books in all their lists. So if a user has 3 lists and 3 books in each. I can accessall 9 books at once.

This works fine thanks to this answer so SO -> https://stackoverflow.com/a/49386095/9277589

How would I go about deleting the books, when I delete the list. Currently the list deletes, but the books don't.

This is how I access the books in my view. $user->WatchedBooks

I have tried this

public function destroy($id){

$user = Auth::user();
$Watchlist = Watchlists::where('id', $id)->first();

if($Watchlist->user_id == Auth::id()){
  $Watchlist->delete();
  return redirect('watchlist');
} else {
  return redirect('watchlist');
}

if($user->WatchedBooks == $user){
  return redirect('watchlist');
} else {
  return redirect('watchlist');
}
  }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2IK0cza
via IFTTT

Aucun commentaire:

Enregistrer un commentaire