Laravel Locale is a package that provide locale switcher for you application.
Install the package
composer require bramalho/laravel-locale
Add the service provider in config/app.php
BRamalho\LaravelLocale\LaravelLocaleServiceProvider::class,
Publish the configs
php artisan vendor:publish --provider 'BRamalho\LaravelLocale\LaravelLocaleServiceProvider'
Register the Middleware in app\Http\Kernel.php
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Bramalho\LaravelLocale\Http\Middleware\Locale;
class Kernel extends HttpKernel
{
// ...
protected $middleware = [
\Illuminate\Session\Middleware\StartSession::class,
Locale::class
];
}
<form method="POST" action="{{ route('locale') }}">
@csrf
<input type="text" name="locale" value="pt">
<button type="submit">Submit</button>
</form>
The Laravel Locale is open-sourced software licensed under the MIT license.