parent
eb6730a9e1
commit
ef0e4018fb
5 changed files with 163 additions and 20 deletions
@ -0,0 +1,63 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Requests\Api; |
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest; |
||||||
|
use Illuminate\Contracts\Validation\Validator; |
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException; |
||||||
|
|
||||||
|
|
||||||
|
class LoginApiRequest 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 [ |
||||||
|
'username' => 'required|email_or_phone', |
||||||
|
'password' => 'required' |
||||||
|
]; |
||||||
|
} |
||||||
|
/** |
||||||
|
* Get the error messages for the defined validation rules. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function messages() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'username.email_or_phone' => 'Tên đăng nhập phải là email hoặc số điện thoại hợp lệ.', |
||||||
|
'username.required' => 'Tên đăng nhập không được để trống.', |
||||||
|
'required.required' => 'Mật khẩu không được để trống.', |
||||||
|
]; |
||||||
|
} |
||||||
|
/** |
||||||
|
* 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)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue