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

82 lines
1.9 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;
use App\Http\Requests\Request;
use App\Models\Client;
use Illuminate\Support\Facades\Log;
class StoreClientRequest extends Request
{
/**
* 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-05-10 08:08:33 +02:00
// $this->sanitize();
/* Ensure we have a client name, and that all emails are unique*/
$rules['name'] = 'required|min:1';
2019-05-10 08:08:33 +02:00
$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
2019-10-06 23:13:16 +02:00
//$rules['settings'] = 'json';
2019-10-05 00:15:57 +02:00
$contacts = request('contacts');
2019-03-28 10:05:13 +01:00
if(is_array($contacts))
{
for ($i = 0; $i < count($contacts); $i++) {
2019-10-02 12:22:10 +02:00
//$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . isset($contacts[$i]['id']);
2019-10-06 10:44:00 +02:00
$rules['contacts.' . $i . '.email'] = 'nullable|email';
}
2019-03-28 10:05:13 +01:00
}
2019-09-11 05:46:23 +02:00
// Log::error($rules);
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-07 08:43:19 +02:00
$input['settings'] = new \stdClass;
2019-05-10 08:08:33 +02:00
$this->replace($input);
}
public function messages()
{
return [
'unique' => ctrans('validation.unique', ['attribute' => 'email']),
//'required' => trans('validation.required', ['attribute' => 'email']),
'contacts.*.email.required' => ctrans('validation.email', ['attribute' => 'email']),
];
}
}