Skip to content

Commit

Permalink
[8.x] Model::delete throw LogicException not Exception (#36914)
Browse files Browse the repository at this point in the history
* Throw LogicException instead of Exception on delete model with missing primary key

* Update Model.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
lachlankrautz and taylorotwell committed Apr 8, 2021
1 parent c351a30 commit 5e0ef03
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Model.php
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e0ef03

Please sign in to comment.