app/Http/Controllers/Auth/LoginController.php
/**
     * Handle an authentication attempt.
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
Handle an authentication attempt.
@param Request $request
@return JsonResponse
@throws ValidationException
Handle an authentication attempt . @param Request $request @return JsonResponse @throws ValidationException
public function login(Request $request): JsonResponse
    {
        $messages = [
            'name.required' => 'Kasutajanimi on kohustuslik!',
            'password.required' => 'Parool on kohustuslik!',
        ];
        $this->validate($request, [
            'name' => 'required',
            'password' => 'required'
        ], $messages);
        if (Auth::attempt($this->getCredentials($request), $request->post('remember_me'))) {
            $request->session()->regenerate();
            return response()->json(new UserResource(Auth::user()));
        }
        $errors = [
            'name' => ['Vale kasutajanimi või parool'],
            'password' => [' ']
        ];
        return response()->json(['errors' => $errors], 401);
    }
public function login ( Request $ request ) : JsonResponse { $ messages = [ 'name.required' => 'Kasutajanimi on kohustuslik!' , 'password.required' => 'Parool on kohustuslik!' , ] ; $ this -> validate ( $ request , [ 'name' => 'required' , 'password' => 'required' ] , $ messages ) ; if ( Auth :: attempt ( $ this -> getCredentials ( $ request ) , $ request -> post ( 'remember_me' ) ) ) { $ request -> session ( ) -> regenerate ( ) ; return response ( ) -> json ( new UserResource ( Auth :: user ( ) ) ) ; } $ errors = [ 'name' => [ 'Vale kasutajanimi või parool'] , 'password' => [ ' ' ] ] ; return response ( ) -> json ( [ 'errors' => $ errors ] , 401 ) ; }
Handle an authentication attempt.
Handle an authentication attempt .