first changes
This commit is contained in:
29
app/Http/Controllers/LocaleController.php
Normal file
29
app/Http/Controllers/LocaleController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user