How can we change the locale of the client side error page in laravel based on the auth locale and without auth locale?

92 views Asked by At

I have to change the language of the page like 404,403 etc in laravel with the locale. This means if the auth has a locale then the locale is the user's locale otherwise default locale.

I have tried this in my handler.php file in the Exception folder. The file path is: App\Exceptions\Handler.php

public function render($request, Throwable $e)
    {
        if (auth()->user()) {
            app()->setLocale(auth()->user()->locale);
        }else if(!auth()->user() && $request->session('locale')) {
            app()->setLocale(session('locale'));
        }else{
            app()->setLocale(config('app.locale'));
        }

        if($e instanceof NotFoundHttpException) {
            return response()->view('errors.404', [], 404);
        }

        return parent::render($request, $e);
    }

After I did this all worked properly but when try to type the route that doesn't exists it shows:=> This page isn’t working example. the test is currently unable to handle this request. HTTP ERROR 500

0

There are 0 answers