You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.0 KiB
79 lines
3.0 KiB
<?php
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
class RegisterApiRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 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<string, mixed>
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'email' => 'required|email|unique:users',
|
|
'fullname' => 'required',
|
|
'phone' => 'required|unique:users|min:10|max:11|regex:/^([0-9\s\-\+\(\)]*)$/',
|
|
'password' => 'required',
|
|
'agents_code' => 'required',
|
|
'role' => 'in:agents',
|
|
'gender' => 'required|in:male,female'
|
|
];
|
|
}
|
|
/**
|
|
* Get the error messages for the defined validation rules.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function messages()
|
|
{
|
|
return [
|
|
'email.unique' => 'Địa chỉ email này đã được sử dụng.',
|
|
'email.required' => 'Đăng ký thất bại, vui lòng gửi lên thông tin Email.',
|
|
'email.email' => 'Đăng ký thất bại, vui lòng nhập đúng định dạng Email',
|
|
'fullname.required' => 'Đăng ký thất bại, vui lòng gửi lên thông tin Họ tên.',
|
|
'phone.unique' => 'Số điện thoại này đã được sử dụng.',
|
|
'phone.required' => 'Đăng ký thất bại, vui lòng gửi lên thông tin Số điện thoại.',
|
|
'phone.min' => 'Đăng ký thất bại, Số điện thoại gồm 10-11 số.',
|
|
'phone.max' => 'Đăng ký thất bại, Số điện thoại gồm 10-11 số.',
|
|
'password.required' => 'Đăng ký thất bại, vui lòng gửi lên thông tin Mật khẩu.',
|
|
'agents_code.required' => 'Đăng ký thất bại, vui lòng gửi lên mã đại lý.',
|
|
'gender.required' => 'Đăng ký thất bại, vui lòng gửi lên thông tin Giới tính.',
|
|
'gender.in' => 'Đăng ký thất bại, vui lòng gửi lên đúng thông tin Giới tính.',
|
|
'role.required' => 'Đăng ký thất bại, vui lòng gửi lên đúng thông tin Vai trò.',
|
|
'role.in' => 'Đăng ký thất bại, Vui lòng gửi lên đúng vai trò đại lý.',
|
|
// Các thông báo lỗi khác
|
|
];
|
|
}
|
|
/**
|
|
* Handle a failed validation attempt.
|
|
*
|
|
* @param \Illuminate\Contracts\Validation\Validator $validator
|
|
* @return void
|
|
*
|
|
* @throws \Illuminate\Http\Exceptions\HttpResponseException
|
|
*/
|
|
protected function failedValidation(Validator $validator)
|
|
{
|
|
throw new HttpResponseException(response()->json([
|
|
'status' => false,
|
|
'msg' => $validator->errors()
|
|
], 200));
|
|
}
|
|
|
|
}
|
|
|