2018-12-05 09:23:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Client;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2019-01-21 15:06:49 +01:00
|
|
|
use App\Models\Client;
|
2018-12-05 09:23:12 +01:00
|
|
|
|
|
|
|
class StoreClientRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
|
2019-01-21 15:06:49 +01:00
|
|
|
public function authorize() : bool
|
2018-12-05 09:23:12 +01:00
|
|
|
{
|
2019-03-27 22:32:50 +01:00
|
|
|
return auth()->user()->can('create', Client::class);
|
2018-12-05 09:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
2018-12-07 11:57:20 +01:00
|
|
|
{
|
|
|
|
/* Ensure we have a client name, and that all emails are unique*/
|
|
|
|
$rules['name'] = 'required';
|
|
|
|
|
|
|
|
$contacts = request('contacts');
|
|
|
|
|
2019-03-28 10:05:13 +01:00
|
|
|
if(is_array($contacts))
|
|
|
|
{
|
|
|
|
|
2018-12-07 11:57:20 +01:00
|
|
|
for ($i = 0; $i < count($contacts); $i++) {
|
|
|
|
$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . isset($contacts[$i]['id']);
|
|
|
|
}
|
|
|
|
|
2019-03-28 10:05:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $rules;
|
2018-12-07 11:57:20 +01:00
|
|
|
|
2018-12-05 09:23:12 +01:00
|
|
|
|
2018-12-07 11:57:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function messages()
|
2018-12-05 09:23:12 +01:00
|
|
|
{
|
|
|
|
return [
|
2019-01-25 11:47:23 +01:00
|
|
|
'unique' => ctrans('validation.unique', ['attribute' => 'email']),
|
2018-12-07 11:57:20 +01:00
|
|
|
//'required' => trans('validation.required', ['attribute' => 'email']),
|
2019-01-25 11:47:23 +01:00
|
|
|
'contacts.*.email.required' => ctrans('validation.email', ['attribute' => 'email']),
|
2018-12-05 09:23:12 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|