30 lines
732 B
PHP
30 lines
732 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
class LocaleController extends Controller
|
|
{
|
|
public function setLocale($locale)
|
|
{
|
|
// Validate supported locales
|
|
$supportedLocales = ['en', 'np']; // Add more locales as needed
|
|
|
|
if (!in_array($locale, $supportedLocales)) {
|
|
abort(400, 'Unsupported locale');
|
|
}
|
|
|
|
// Set the application locale
|
|
App::setLocale($locale);
|
|
|
|
// Store the locale in session or cookie
|
|
session()->put('locale', $locale);
|
|
|
|
// Redirect back or to a specific route after setting locale
|
|
return Redirect::back();
|
|
}
|
|
}
|