2021-02-15 22:14:30 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2023-08-20 06:36:22 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2021-02-15 22:14:30 +01:00
|
|
|
*
|
2023-08-20 06:36:22 +02:00
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
2021-02-15 22:14:30 +01:00
|
|
|
*
|
2023-08-20 06:36:22 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-02-15 22:14:30 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-02-15 22:14:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Task;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
|
|
|
|
class UploadTaskRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize() : bool
|
|
|
|
{
|
2023-08-20 06:36:22 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
return $user->can('edit', $this->task);
|
2021-02-15 22:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
2023-08-20 10:18:55 +02:00
|
|
|
$rules = [];
|
|
|
|
|
|
|
|
if ($this->file('documents') && is_array($this->file('documents'))) {
|
|
|
|
$rules['documents.*'] = $this->file_validation;
|
|
|
|
} elseif ($this->file('documents')) {
|
|
|
|
$rules['documents'] = $this->file_validation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->file('file') && is_array($this->file('file'))) {
|
|
|
|
$rules['file.*'] = $this->file_validation;
|
|
|
|
} elseif ($this->file('file')) {
|
|
|
|
$rules['file'] = $this->file_validation;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rules['is_public'] = 'sometimes|boolean';
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return $rules;
|
2021-02-15 22:14:30 +01:00
|
|
|
}
|
2023-08-20 06:36:22 +02:00
|
|
|
|
|
|
|
public function prepareForValidation()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
2023-10-26 04:57:44 +02:00
|
|
|
if(isset($input['is_public'])) {
|
2023-08-20 06:36:22 +02:00
|
|
|
$input['is_public'] = $this->toBoolean($input['is_public']);
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|
2023-08-20 06:36:22 +02:00
|
|
|
|
|
|
|
$this->replace($input);
|
|
|
|
}
|
|
|
|
|
2021-02-15 22:14:30 +01:00
|
|
|
}
|