50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\Lead\App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Modules\Lead\App\Models\Lead;
|
|
|
|
class LeadRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'fullname' => ['nullable', 'string', 'max:255'],
|
|
'company' => ['nullable', 'string', 'max:255'],
|
|
'email' => ['required', 'email', 'max:255', Rule::unique('leads', 'email')->ignore($this->route('uuid'), 'uuid')],
|
|
'phone' => ['nullable', 'string', 'max:30'],
|
|
'address' => ['nullable', 'string', 'max:1000'],
|
|
'status' => ['nullable', Rule::in(Lead::STATUSES)],
|
|
'customer_id' => ['nullable', 'integer', 'exists:customers,id'],
|
|
'receives_invoice_emails' => ['nullable', 'boolean'],
|
|
'receives_domain_emails' => ['nullable', 'boolean'],
|
|
'receives_support_emails' => ['nullable', 'boolean'],
|
|
'receives_product_emails' => ['nullable', 'boolean'],
|
|
'receives_general_emails' => ['nullable', 'boolean'],
|
|
'note' => ['nullable', 'string', 'max:5000'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'email.required' => 'Email là bắt buộc.',
|
|
'email.unique' => 'Email này đã có trong danh sách khách tiềm năng.',
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if ($this->has('email')) {
|
|
$this->merge(['email' => strtolower(trim((string) $this->input('email')))]);
|
|
}
|
|
}
|
|
}
|