1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/app/Http/Requests/Vendor/UpdateVendorRequest.php

108 lines
3.4 KiB
PHP
Raw Normal View History

<?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)
*
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;
use App\Utils\Traits\ChecksEntityStatus;
use App\Utils\Traits\MakesHash;
2021-03-19 23:51:52 +01:00
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
{
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->vendor);
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
2022-12-08 00:38:52 +01:00
$rules['country_id'] = 'integer';
if ($this->number) {
$rules['number'] = Rule::unique('vendors')->where('company_id', $user->company()->id)->ignore($this->vendor->id);
}
2022-12-08 00:38:52 +01:00
2023-10-26 12:09:22 +02:00
$rules['contacts'] = 'bail|array';
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
$rules['contacts.*.password'] = [
'bail',
'nullable',
'sometimes',
'string',
'min:7', // must be at least 10 characters in length
'regex:/[a-z]/', // must contain at least one lowercase letter
'regex:/[A-Z]/', // must contain at least one uppercase letter
'regex:/[0-9]/', // must contain at least one digit
//'regex:/[@$!%*#?&.]/', // must contain a special character
];
2022-12-14 01:09:14 +01:00
$rules['currency_id'] = 'bail|sometimes|exists:currencies,id';
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['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,company,partnership,trust,charity,government,other';
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']),
];
}
2022-06-24 03:55:41 +02:00
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']);
}
2023-02-16 02:36:09 +01:00
if (array_key_exists('country_id', $input) && is_null($input['country_id'])) {
2022-12-08 00:38:52 +01:00
unset($input['country_id']);
2023-02-16 02:36:09 +01:00
}
2022-12-08 00:38:52 +01:00
2022-07-22 06:07:51 +02:00
$input = $this->decodePrimaryKeys($input);
$this->replace($input);
}
}