parent
e9ba22b3ba
commit
28e7344300
2 changed files with 76 additions and 8 deletions
@ -0,0 +1,66 @@ |
|||||||
|
<?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', |
||||||
|
]; |
||||||
|
} |
||||||
|
/** |
||||||
|
* 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.', |
||||||
|
// 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, |
||||||
|
'errors' => $validator->errors() |
||||||
|
], 200)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue