1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Requests/Client/StoreClientRequest.php

91 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Client;
2019-10-29 10:51:23 +01:00
use App\DataMapper\ClientSettings;
use App\Http\Requests\Request;
2019-10-29 10:51:23 +01:00
use App\Http\ValidationRules\ValidSettingsRule;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
class StoreClientRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Client::class);
}
public function rules()
{
2019-10-29 10:51:23 +01:00
$this->sanitize();
2019-05-10 08:08:33 +02:00
/* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1';
2019-10-08 13:17:05 +02:00
$rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id;
2019-10-29 10:51:23 +01:00
$rules['settings'] = new ValidSettingsRule();
$rules['contacts.*.email'] = 'distinct';
$contacts = request('contacts');
2019-03-28 10:05:13 +01:00
if(is_array($contacts))
{
for ($i = 0; $i < count($contacts); $i++) {
//$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
}
2019-03-28 10:05:13 +01:00
}
return $rules;
}
2019-05-10 08:08:33 +02:00
public function sanitize()
{
$input = $this->all();
2019-10-29 10:51:23 +01:00
$input['settings'] = ClientSettings::defaults();
2019-10-07 08:43:19 +02:00
if(isset($input['group_settings_id']))
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
2019-05-10 08:08:33 +02:00
$this->replace($input);
return $this->all();
2019-05-10 08:08:33 +02:00
}
public function messages()
{
return [
'unique' => ctrans('validation.unique', ['attribute' => 'email']),
//'required' => trans('validation.required', ['attribute' => 'email']),
'contacts.*.email.required' => ctrans('validation.email', ['attribute' => 'email']),
];
}
}