2020-01-20 02:31:58 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
class UpdateVendorRequest extends Request
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use ChecksEntityStatus;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
/**
|
|
|
|
* 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|nullable';
|
2022-06-21 11:57:17 +02:00
|
|
|
|
|
|
|
if ($this->number) {
|
2021-03-19 23:51:52 +01:00
|
|
|
$rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2020-01-20 02:31:58 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
// if($this->id_number)
|
2022-03-10 10:48:14 +01:00
|
|
|
// $rules['id_number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id);
|
2021-03-19 23:51:52 +01:00
|
|
|
|
|
|
|
$rules['contacts.*.email'] = 'nullable|distinct';
|
2022-03-10 10:48:14 +01:00
|
|
|
// $rules['id_number'] = 'unique:vendors,id_number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
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']),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepareForValidation()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-10-15 23:17:31 +02:00
|
|
|
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
|
|
|
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
$this->replace($input);
|
|
|
|
}
|
|
|
|
}
|