megahunt.test/app/Services/UserTrashService.php

43 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:40:57 +02:00
) {}
2024-08-30 06:16:16 +02:00
2024-08-30 09:40:57 +02:00
public function moveUsersToTrash(array $ids): bool|array
2024-08-30 06:16:16 +02:00
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
2024-08-30 09:40:57 +02:00
return User::whereIn('id', $ids)->update(['deleted_at' => now()->toDateTimeImmutable()]);
2024-08-30 06:16:16 +02:00
}
2024-08-30 09:40:57 +02:00
public function moveUsersFromTrash(array $ids): bool|array
2024-08-30 06:16:16 +02:00
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
2024-08-30 09:40:57 +02:00
return User::whereIn('id', $ids)->update(['deleted_at' => null]);
2024-08-30 06:16:16 +02:00
}
2024-08-30 09:40:57 +02:00
public function cleanUsersFromTrash(array $ids): bool|null|array
2024-08-30 06:16:16 +02:00
{
$unexisting = $this->userService->getUnexistingIds($ids);
if (is_array($unexisting)) {
return $unexisting;
}
return User::whereIn('id', $ids)->whereNotNull('deleted_at')->delete();
}
}