Jelajahi Sumber

Loop over books to delete comments when deleting an author

axkuhta 1 tahun lalu
induk
melakukan
15c64e7950

+ 6 - 1
app/Http/Controllers/AuthorController.php

@@ -71,8 +71,13 @@ class AuthorController extends Controller {
 	}
 
 	function drop(Author $author) {
-		$author->books()->delete();
+		foreach($author->books as $book) {
+			$book->comments()->delete();
+			$book->delete();
+		}
+
 		$author->delete();
+
 		return view("success");
 	}
 }

+ 1 - 0
app/Http/Controllers/BookController.php

@@ -81,6 +81,7 @@ class BookController extends Controller {
 	}
 
 	function drop(Book $book) {
+		$book->comments()->delete();
 		$book->delete();
 		return view("success");
 	}