Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/SoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function forceDelete()
protected function performDeleteOnModel()
{
if ($this->forceDeleting) {
$this->exists = false;

return $this->setKeysForSaveQuery($this->newModelQuery())->forceDelete();
return tap($this->setKeysForSaveQuery($this->newModelQuery())->forceDelete(), function () {
$this->exists = false;
});
}

return $this->runSoftDelete();
Expand Down
37 changes: 37 additions & 0 deletions tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Pagination\CursorPaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Mockery;
use PHPUnit\Framework\TestCase;

class DatabaseEloquentSoftDeletesIntegrationTest extends TestCase
Expand Down Expand Up @@ -189,6 +190,42 @@ public function testForceDeleteActuallyDeletesRecords()
$this->assertEquals(1, $users->first()->id);
}

public function testForceDeleteUpdateExistsProperty()
{
$this->createUsers();
$user = SoftDeletesTestUser::find(2);

$this->assertTrue($user->exists);

$user->forceDelete();

$this->assertFalse($user->exists);
}

public function testForceDeleteDoesntUpdateExistsPropertyIfFailed()
{
$user = new class() extends SoftDeletesTestUser
{
public $exists = true;

public function newModelQuery()
{
return Mockery::spy(parent::newModelQuery(), function (Mockery\MockInterface $mock) {
$mock->shouldReceive('forceDelete')->andThrow(new \Exception());
});
}
};

$this->assertTrue($user->exists);

try {
$user->forceDelete();
} catch (\Exception $exception) {
}

$this->assertTrue($user->exists);
}

public function testRestoreRestoresRecords()
{
$this->createUsers();
Expand Down