From bacfd8c72918f640230bf7096553f2a28756665d Mon Sep 17 00:00:00 2001 From: Krisan Alfa Timur Date: Fri, 26 May 2017 17:22:14 +0700 Subject: [PATCH] [FIX] Translation not loaded due to misconfiguration. --- .env.example | 1 + app/Exceptions/Handler.php | 40 +++----------------- app/Http/Controllers/Auth/AuthController.php | 37 ++++-------------- config/app.php | 27 ++++++++++++- 4 files changed, 39 insertions(+), 66 deletions(-) diff --git a/.env.example b/.env.example index 55a9f59..eed189e 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ APP_ENV=local APP_DEBUG=true +API_DEBUG=true APP_KEY=aaaabbbbccccddddeeeeffffgggghhhh DB_CONNECTION=mysql diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 4b9f797..7a3f3ae 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,14 +3,11 @@ namespace App\Exceptions; use Exception; -use Illuminate\Support\Arr; -use Illuminate\Support\Str; -use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Symfony\Component\HttpKernel\Exception\HttpException; use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; +use Symfony\Component\HttpKernel\Exception\HttpException; class Handler extends ExceptionHandler { @@ -25,54 +22,27 @@ class Handler extends ExceptionHandler ModelNotFoundException::class, ValidationException::class, ]; - /** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $e + * @param \Exception $e + * @return void */ public function report(Exception $e) { parent::report($e); } - /** * Render an exception into an HTTP response. * - * @param \Illuminate\Http\Request $request - * @param \Exception $e - * + * @param \Illuminate\Http\Request $request + * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { - if ($e instanceof HttpException) { - return new JsonResponse([ - 'message' => $e->getMessage() ?: $this->getMessageFromClassName($e), - ], $e->getStatusCode()); - } - return parent::render($request, $e); } - - /** - * Get Message From Class Name. - * - * @param HttpException $e - * - * @return string - */ - protected function getMessageFromClassName(HttpException $e) - { - $class = get_class($e); - $file = Arr::last(explode('\\', $class)); - - return Str::snake(str_ireplace( - ['HttpException', 'Exception'], - ['', ''], - $file - )); - } } diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index eb8d742..20cbbe9 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -8,6 +8,7 @@ use Tymon\JWTAuth\Facades\JWTAuth; use App\Http\Controllers\Controller; use Tymon\JWTAuth\Exceptions\JWTException; +use Illuminate\Validation\ValidationException; use Illuminate\Http\Exception\HttpResponseException; class AuthController extends Controller @@ -22,9 +23,12 @@ class AuthController extends Controller public function postLogin(Request $request) { try { - $this->validatePostLoginRequest($request); - } catch (HttpResponseException $e) { - return $this->onBadRequest(); + $this->validate($request, [ + 'email' => 'required|email|max:255', + 'password' => 'required', + ]); + } catch (ValidationException $e) { + return $e->getResponse(); } try { @@ -43,33 +47,6 @@ public function postLogin(Request $request) return $this->onAuthorized($token); } - /** - * Validate authentication request. - * - * @param Request $request - * @return void - * @throws HttpResponseException - */ - protected function validatePostLoginRequest(Request $request) - { - $this->validate($request, [ - 'email' => 'required|email|max:255', - 'password' => 'required', - ]); - } - - /** - * What response should be returned on bad request. - * - * @return JsonResponse - */ - protected function onBadRequest() - { - return new JsonResponse([ - 'message' => 'bad_request' - ], Response::HTTP_BAD_REQUEST); - } - /** * What response should be returned on invalid credentials. * diff --git a/config/app.php b/config/app.php index c130c64..0b627b0 100644 --- a/config/app.php +++ b/config/app.php @@ -1,6 +1,7 @@ env('APP_KEY'), + 'key' => env('APP_KEY', 'aaaabbbbccccddddeeeeffffgggghhhh'), 'cipher' => 'AES-256-CBC', + + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ + 'locale' => env('APP_LOCALE', 'en'), + /* + |-------------------------------------------------------------------------- + | Application Fallback Locale + |-------------------------------------------------------------------------- + | + | The fallback locale determines the locale to use when the current one + | is not available. You may change the value to correspond to any of + | the language folders that are provided through your application. + | + */ + 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), + ];