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.
70 lines
2.0 KiB
70 lines
2.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',
|
|
'password' => 'required',
|
|
'agents_code' => 'required',
|
|
];
|
|
}
|
|
/**
|
|
* 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' => 'Địa chỉ email không được trống.',
|
|
'fullname.required' => 'Họ tên không được trống.',
|
|
'phone.unique' => 'Số điện thoại này đã được sử dụng.',
|
|
'phone.required' => 'Số điện thoại không được trống.',
|
|
'password.required' => 'Mật khẩu không được trống.',
|
|
'agents_code.required' => 'Đăng ký thất bại, vui lòng gửi lên mã đạ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,
|
|
'message' => $validator->errors()
|
|
], 200));
|
|
}
|
|
|
|
}
|
|
|