mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
projects
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AddUser
|
||||
@ -14,6 +15,8 @@ class AddUser
|
||||
*/
|
||||
public function add(Project $project, array $input): void
|
||||
{
|
||||
Validator::make($input, self::rules($project))->validate();
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::query()->findOrFail($input['user']);
|
||||
|
||||
|
@ -13,6 +13,8 @@ class CreateProject
|
||||
*/
|
||||
public function create(User $user, array $input): Project
|
||||
{
|
||||
Validator::make($input, self::rules())->validate();
|
||||
|
||||
if (isset($input['name'])) {
|
||||
$input['name'] = strtolower((string) $input['name']);
|
||||
}
|
||||
|
@ -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.'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user