1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-17 00:22:51 +01:00
invoiceninja/app/Http/Requests/Project/UpdateProjectRequest.php

80 lines
2.0 KiB
PHP
Raw Normal View History

2020-10-08 00:25:39 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2020-10-08 00:25:39 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-10-08 00:25:39 +02:00
*/
namespace App\Http\Requests\Project;
use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus;
2020-12-02 09:59:45 +01:00
use Illuminate\Validation\Rule;
2020-10-08 00:25:39 +02:00
class UpdateProjectRequest extends Request
{
use ChecksEntityStatus;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
2024-01-14 05:05:00 +01:00
public function authorize(): bool
2020-10-08 00:25:39 +02:00
{
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->project);
2020-10-08 00:25:39 +02:00
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
2020-11-25 15:19:52 +01:00
if (isset($this->number)) {
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id);
2020-11-25 15:19:52 +01:00
}
2020-10-29 12:01:37 +01:00
2023-03-18 08:24:56 +01:00
if ($this->file('documents') && is_array($this->file('documents'))) {
2023-02-27 10:12:59 +01:00
$rules['documents.*'] = $this->file_validation;
2023-03-18 08:24:56 +01:00
} elseif ($this->file('documents')) {
2023-02-27 10:12:59 +01:00
$rules['documents'] = $this->file_validation;
2024-02-16 19:57:15 +01:00
}else {
$rules['documents'] = 'bail|sometimes|array';
2023-03-18 08:24:56 +01:00
}
2023-02-27 10:12:59 +01:00
if ($this->file('file') && is_array($this->file('file'))) {
$rules['file.*'] = $this->file_validation;
} elseif ($this->file('file')) {
$rules['file'] = $this->file_validation;
}
return $this->globalRules($rules);
2020-10-08 00:25:39 +02:00
}
2022-06-24 03:55:41 +02:00
public function prepareForValidation()
2020-10-08 00:25:39 +02:00
{
2020-11-25 15:19:52 +01:00
$input = $this->decodePrimaryKeys($this->all());
2020-10-08 00:25:39 +02:00
2020-11-25 15:19:52 +01:00
if (isset($input['client_id'])) {
2020-11-11 21:42:20 +01:00
unset($input['client_id']);
2020-11-25 15:19:52 +01:00
}
2020-11-11 21:42:20 +01:00
if (array_key_exists('color', $input) && is_null($input['color'])) {
$input['color'] = '';
}
2021-01-07 23:25:00 +01:00
2020-10-08 00:25:39 +02:00
$this->replace($input);
}
}