1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Http/Requests/Vendor/UploadVendorRequest.php

60 lines
1.4 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\Vendor;
use App\Http\Requests\Request;
class UploadVendorRequest 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
{
return auth()->user()->can('edit', $this->vendor);
}
public function rules()
{
$rules = [];
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;
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;
}
$rules['is_public'] = 'sometimes|boolean';
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);
}
}