TaskA/app/Http/Controllers/LocaleController.php

30 lines
732 B
PHP
Raw Normal View History

2024-06-16 08:11:32 +00:00
<?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();
}
}