php - Overriding custom login error messages in laravel 5.2 -


i've been struggling laravel 5.2 login function messages. i've override default sendfailedloginresponse function in authcontroller works failed attempts.

but need override validate function response not figure out how that. not want override default login functionality in authcontrller , want stick same login function.

the reason overriding validate function making angular app , want response in json format custom keys.

currently default login function in illuminate\foundation\auth\authenticateusers.php

public function login(request $request) {     $this->validate($request, [         $this->loginusername() => 'required', 'password' => 'required',     ]);     // if class using throttleslogins trait, can automatically throttle     // login attempts application. we'll key username ,     // ip address of client making these requests application.     $throttles = $this->isusingthrottlesloginstrait();      if ($throttles && $this->hastoomanyloginattempts($request)) {         return $this->sendlockoutresponse($request);     }      $credentials = $this->getcredentials($request);      if (auth::guard($this->getguard())->attempt($credentials, $request->has('remember'))) {         return $this->handleuserwasauthenticated($request, $throttles);     }      // if login attempt unsuccessful increment number of attempts     // login , redirect user login form. of course, when     // user surpasses maximum number of attempts locked out.     if ($throttles) {         $this->incrementloginattempts($request);     }      return $this->sendfailedloginresponse($request); } 

i want response in below sendfailedresponse function in authcontroller

 /**  * failed request response  *  * @param null  * @return null  */ public function sendfailedloginresponse() {     return response()->json( [ 'status' => false, 'message' => $this->getfailedloginmessage() ]); } 

thanks

i don't know angular , handling json on laravel had similar problem while creating custom error message postlogin function. take @ code, perhaps within form request.

this authcontroller.php

use app\http\requests\loginformrequest;  /**  * handle login request application.  *  * @param  \illuminate\http\request  $request  * @return \illuminate\http\response  */ public function postlogin(loginformrequest $request) {     return $this->login($request); } 

try using form request on function postlogin

class loginformrequest extends request {   /**    * determine if user authorized make request.    *    * @return bool    */   public function authorize()   {     return true;   }    /**    * validation rules apply request.    *    * @return array    */   public function rules()   {     return [         'email'            => 'required|email',         'password'         => 'required|min:6',     ];   }    public function messages()   {     return [         'required'  => 'your :attribute required.',         'min'  => ':attribute must @ least :min characters in length.',         'email' => 'please type valid email address.',     ];   } } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -