megahunt.test/app/Services/UserTrashService.php

44 lines
1.1 KiB
PHP

<?php
namespace App\Services;
use App\Models\User;
class UserTrashService
{
public function __construct(
private UserService $userService
) {
}
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();
}
}