ok

Mini Shell

Direktori : /home2/selectio/www/billingsoftwarenew/core/app/Http/Middleware/
Upload File :
Current File : /home2/selectio/www/billingsoftwarenew/core/app/Http/Middleware/LanguageMiddleware.php

<?php

namespace App\Http\Middleware;

use App\Constants\Status;
use App\Models\Language;
use Closure;

class LanguageMiddleware {
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {
        session()->put('lang', $this->getCode());
        app()->setLocale(session('lang',  $this->getCode()));
        return $next($request);
    }

    public function getCode() {
        if (session()->has('lang')) {
            return session('lang');
        }
        $language = Language::where('is_default', Status::YES)->first();
        return $language ? $language->code : 'en';
    }
}

Zerion Mini Shell 1.0