31 lines
715 B
PHP
31 lines
715 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
class LoginRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'email' => ['required', 'email'],
|
|
'password' => ['required', 'string', 'min:8']
|
|
];
|
|
}
|
|
|
|
protected function failedValidation(Validator $validator)
|
|
{
|
|
throw new HttpResponseException(response()->json([
|
|
'error' => '驗證失敗',
|
|
'messages' => $validator->errors()
|
|
], 422));
|
|
}
|
|
}
|