1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Requests/Task/UploadTaskRequest.php

64 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
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
*/
2024-01-14 05:05:00 +01:00
public function authorize(): bool
{
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->task);
}
public function rules()
{
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
2024-03-19 00:46:57 +01:00
$rules['documents.*'] = $this->fileValidation();
} elseif ($this->file('documents')) {
2024-03-19 00:46:57 +01:00
$rules['documents'] = $this->fileValidation();
}
if ($this->file('file') && is_array($this->file('file'))) {
2024-03-19 00:46:57 +01:00
$rules['file.*'] = $this->fileValidation();
} elseif ($this->file('file')) {
2024-03-19 00:46:57 +01:00
$rules['file'] = $this->fileValidation();
}
$rules['is_public'] = 'sometimes|boolean';
2024-01-14 05:05:00 +01:00
return $rules;
}
public function prepareForValidation()
{
$input = $this->all();
2023-10-26 04:57:44 +02:00
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
2023-10-26 04:57:44 +02:00
}
$this->replace($input);
}
}