-
Notifications
You must be signed in to change notification settings - Fork 1
Soft Deletes
Gilberto Junior edited this page Dec 5, 2019
·
11 revisions
Avaliable for classes that extends CodeHappy\DataLayer\Repository
.
<?php
namespace App\Repositories;
use CodeHappy\DataLayer\Repository;
use CodeHappy\DataLayer\Traits\SoftDeletes;
class UserRepository extends Repository
{
use SoftDeletes;
}
The same found in the Laravel Documentation.
Retrieve all records, including records from the trash.
public function withTrashed(): self;
$allRecords = $repository
->withTrashed()
->fetch();
Retrieve only the records from trash.
public function onlyTrashed(): self;
$allRecords = $repository
->onlyTrashed()
->where('id < 1000')
->fetch();
Restore the trashed records.
public function restoreFromTrash(): bool|null
$restored = $repository
->onlyTrashed()
->restoreFromTrash();
if ($restored === null) {
echo 'No registers found';
} elseif ($restored === true) {
echo 'Registers recovered';
}
by c0dehappy