59 lines
1.5 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2019-11-16 10:21:14 +03:00
namespace App\Http\Requests\Common;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\FormRequest;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
class Contact extends FormRequest
2017-09-14 22:21:00 +03:00
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2019-11-16 10:21:14 +03:00
$email = '';
2017-09-14 22:21:00 +03:00
$required = '';
2019-11-16 10:21:14 +03:00
$type = $this->request->get('type', 'customer');
$company_id = $this->request->get('company_id');
2017-09-14 22:21:00 +03:00
// Check if store or update
if ($this->getMethod() == 'PATCH') {
2019-11-16 10:21:14 +03:00
$id = is_numeric($this->$type) ? $this->$type : $this->$type->getAttribute('id');
2017-09-14 22:21:00 +03:00
} else {
$id = null;
}
2020-03-04 15:13:40 +03:00
if (($this->request->get('create_user', 'false') === 'true') && empty($this->request->get('user_id'))) {
2017-09-14 22:21:00 +03:00
$required = 'required|';
}
if (!empty($this->request->get('email'))) {
2019-11-16 10:21:14 +03:00
$email = 'email|unique:contacts,NULL,' . $id . ',id,company_id,' . $company_id . ',type,' . $type . ',deleted_at,NULL';
}
2017-09-14 22:21:00 +03:00
return [
2019-11-16 10:21:14 +03:00
'type' => 'required|string',
2017-09-14 22:21:00 +03:00
'name' => 'required|string',
'email' => $email,
2019-11-16 10:21:14 +03:00
'user_id' => 'integer|nullable',
'currency_code' => 'required|string|currency',
2017-09-14 22:21:00 +03:00
'password' => $required . 'confirmed',
2018-06-30 12:33:05 +03:00
'enabled' => 'integer|boolean',
2017-09-14 22:21:00 +03:00
];
}
}