This commit is contained in:
Saeed Vaziry
2025-05-15 14:23:26 +03:00
parent a81e9b18b7
commit b8ba83949b
47 changed files with 1536 additions and 980 deletions

View File

@ -4,21 +4,29 @@
use App\Models\Project;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class DeleteProject
{
public function delete(User $user, Project $project): void
/**
* @param array<string, mixed> $input
*/
public function delete(User $user, Project $project, array $input): void
{
Validator::make($input, [
'name' => 'required',
])->validate();
if ($user->projects()->count() === 1) {
throw ValidationException::withMessages([
'project' => __('Cannot delete the last project.'),
'name' => __('Cannot delete the last project.'),
]);
}
if ($user->current_project_id == $project->id) {
throw ValidationException::withMessages([
'project' => __('Cannot delete your current project.'),
'name' => __('Cannot delete your current project.'),
]);
}