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.
63 lines
1.6 KiB
63 lines
1.6 KiB
<?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));
|
|
}
|
|
|
|
}
|
|
|