diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 763cd46f..d9c88396 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -378,6 +378,19 @@ abstract class Model { return $result; } + /** + * Delete the model from the database. + * + * @return int + */ + public function delete() + { + if ($this->exists) + { + return $this->query()->where(static::$key, '=', $this->get_key())->delete(); + } + } + /** * Set the update and creation timestamps on the model. * diff --git a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php index 225f7eb8..7453a02f 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -125,9 +125,7 @@ class Has_Many_And_Belongs_To extends Relationship { */ public function delete() { - $id = $this->base->get_key(); - - return $this->joining_table()->where($this->foreign_key(), '=', $id)->delete(); + return $this->pivot()->delete(); } /**