mirror of
https://github.com/zoe-may/TDoG-Skin.git
synced 2024-11-24 05:42:19 +08:00
35 lines
607 B
PHP
Executable File
35 lines
607 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SetAppLocale
|
|
{
|
|
protected Request $request;
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
$this->request = $request;
|
|
}
|
|
|
|
public function handle($event)
|
|
{
|
|
/** @var User */
|
|
$user = $event->user;
|
|
|
|
if ($this->request->has('lang')) {
|
|
$user->locale = $this->request->input('lang');
|
|
$user->save();
|
|
|
|
return;
|
|
}
|
|
|
|
$locale = $user->locale;
|
|
if ($locale) {
|
|
app()->setLocale($locale);
|
|
}
|
|
}
|
|
}
|