megahunt.test/app/Services/UserTrashService.php

45 lines
1.1 KiB
PHP
Raw Normal View History

2024-08-30 06:16:16 +02:00
<?php
namespace App\Services;
2024-08-30 09:37:24 +02:00
2024-08-30 06:16:16 +02:00
use App\Models\User;
class UserTrashService
{
public function __construct(
private UserService $userService
) {
}
2024-08-30 09:37:24 +02:00
2024-08-30 06:16:16 +02:00
public function moveUsersToTrash(array $ids): bool | array
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
return User::whereIn('id', $ids)->update([ 'deleted_at' => now()->toDateTimeImmutable() ]);
}
public function moveUsersFromTrash(array $ids): bool | array
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
return User::whereIn('id', $ids)->update([ 'deleted_at' => null ]);
}
public function cleanUsersFromTrash(array $ids): bool | null | array
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
return User::whereIn('id', $ids)->whereNotNull('deleted_at')->delete();
}
}