Register Middleware in Kernel by adding
\App\Http\Middleware\LocalizeViewPath::class
to $middlewareGroup array
Now you have to wrap all of your views language based
- resources/views/en
- resources/views/fr
- resources/views/de ...
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\View; | |
class LocalizeViewPath { | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) { | |
$locale = app()->getLocale(); | |
$viewPath = resource_path('views/' . $locale); | |
View::addLocation($viewPath); | |
return $next($request); | |
} | |
} |