mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace App\Http\Requests\Vendor;
|
|
|
|
use App\Http\Requests\Request;
|
|
use App\Utils\Traits\ChecksEntityStatus;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateVendorRequest extends Request
|
|
{
|
|
use MakesHash;
|
|
use ChecksEntityStatus;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize() : bool
|
|
{
|
|
return auth()->user()->can('edit', $this->vendor);
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
/* Ensure we have a client name, and that all emails are unique*/
|
|
|
|
$rules['country_id'] = 'integer';
|
|
|
|
if ($this->number) {
|
|
$rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id);
|
|
}
|
|
|
|
$rules['contacts.*.email'] = 'nullable|distinct';
|
|
$rules['currency_id'] = 'bail|sometimes|exists:currencies,id';
|
|
|
|
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;
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public function messages()
|
|
{
|
|
return [
|
|
'email' => ctrans('validation.email', ['attribute' => 'email']),
|
|
'name.required' => ctrans('validation.required', ['attribute' => 'name']),
|
|
'required' => ctrans('validation.required', ['attribute' => 'email']),
|
|
];
|
|
}
|
|
|
|
public function prepareForValidation()
|
|
{
|
|
$input = $this->all();
|
|
|
|
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
|
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
|
}
|
|
|
|
if (array_key_exists('country_id', $input) && is_null($input['country_id'])) {
|
|
unset($input['country_id']);
|
|
}
|
|
|
|
$input = $this->decodePrimaryKeys($input);
|
|
|
|
$this->replace($input);
|
|
}
|
|
}
|