Aknaproff/app/Http/Controllers/LocaleController.php
2024-03-06 23:11:10 +05:00

32 lines
687 B
PHP

<?php
namespace App\Http\Controllers;
use App\UserSetting;
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);
$userSetting = UserSetting::where('user_id', auth()->user()->id)->first();
if (!empty($userSetting)) {
$userSetting->update([
'language' => $locale
]);
}
return redirect()->back();
}
}