<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                1.創建驗證文件。 ``` php artisan module:make-request LoginRequest AuthAdmin ``` 2.編寫驗證文件。 ``` <?php namespace Modules\AuthAdmin\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class LoginRequest extends FormRequest { /** * php artisan module:make-request LoginRequest AuthAdmin */ /** * 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 */ public function rules() { return [ 'username' => 'required|regex:/^[a-zA-Z0-9]{4,14}$/', 'password' => 'required|regex:/^[a-zA-Z0-9]{4,14}$/' ]; } public function messages(){ return [ 'username.required' => '請輸入用戶名!', 'username.regex' => '用戶名必須4到14位的數字或字母!', 'password.required' => '請輸入密碼!', 'password.regex' => '密碼必須4到14位的數字或字母!', ]; } } ``` 3.引用驗證文件。 ``` <?php namespace Modules\AuthAdmin\Http\Controllers\v1; use Illuminate\Http\Request; use Modules\AuthAdmin\Http\Requests\LoginRequest; use Modules\AuthAdmin\Models\AuthAdmin as AuthAdminModel; class LoginController extends CommonController { /** * @name 用戶登錄 * @method POST * @param username 賬號 * @param password 密碼 */ public function login(LoginRequest $request) { return $request->all(); return (new AuthAdminModel())->login($request->all()); } } ``` 4。修改app\Exceptions\Handler.php。 ``` <?php namespace App\Exceptions; use Exception; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Validation\ValidationException; class Handler extends ExceptionHandler { /** * A list of the exception types that are not reported. * * @var array */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed for validation exceptions. * * @var array */ protected $dontFlash = [ 'password', 'password_confirmation', ]; /** * Report or log an exception. * * @param \Exception $exception * @return void * * @throws \Exception */ public function report(Exception $exception) { parent::report($exception); } /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * @return \Symfony\Component\HttpFoundation\Response * * @throws \Exception */ public function render($request, Exception $exception) { if($request->is("api/*")){ //如果錯誤是 ValidationException的一個實例,說明是一個驗證的錯誤 if($exception instanceof ValidationException){ $result = [ "code"=>4222, "msg"=>array_values($exception->errors())[0][0], ]; return response()->json($result,400); } } return parent::render($request, $exception); } } ``` 視頻鏈接 ```[youku] XNDU0MDUxNDgyMA ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看