From 5e0ef03e9fd664a31d0150df080df8e6549e2ef8 Mon Sep 17 00:00:00 2001 From: Lachlan Krautz Date: Thu, 8 Apr 2021 22:42:49 +1000 Subject: [PATCH] [8.x] Model::delete throw LogicException not Exception (#36914) * Throw LogicException instead of Exception on delete model with missing primary key * Update Model.php Co-authored-by: Taylor Otwell --- src/Illuminate/Database/Eloquent/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 62fcd058e258..245a103bce40 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -3,7 +3,6 @@ namespace Illuminate\Database\Eloquent; use ArrayAccess; -use Exception; use Illuminate\Contracts\Queue\QueueableCollection; use Illuminate\Contracts\Queue\QueueableEntity; use Illuminate\Contracts\Routing\UrlRoutable; @@ -20,6 +19,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Traits\ForwardsCalls; use JsonSerializable; +use LogicException; abstract class Model implements Arrayable, ArrayAccess, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable { @@ -1097,14 +1097,14 @@ public static function destroy($ids) * * @return bool|null * - * @throws \Exception + * @throws \LogicException */ public function delete() { $this->mergeAttributesFromClassCasts(); if (is_null($this->getKeyName())) { - throw new Exception('No primary key defined on model.'); + throw new LogicException('No primary key defined on model.'); } // If the model doesn't exist, there is nothing to delete so we'll just return