Aknaproff/app/Http/Controllers/LocaleController.php

32 lines
687 B
PHP
Raw Normal View History

2024-03-04 04:33:00 +00:00
<?php
namespace App\Http\Controllers;
2024-03-06 18:11:10 +00:00
use App\UserSetting;
2024-03-04 04:33:00 +00:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class LocaleController extends Controller
{
public function __invoke($locale) {
if (! in_array($locale, ['en', 'ru', 'est'])) {
abort(400);
}
Session::put('locale', $locale);
app()->setLocale($locale);
2024-03-06 18:11:10 +00:00
$userSetting = UserSetting::where('user_id', auth()->user()->id)->first();
if (!empty($userSetting)) {
$userSetting->update([
'language' => $locale
]);
}
2024-03-04 04:33:00 +00:00
return redirect()->back();
}
}