Compare commits
4 Commits
main
...
laravel-12
| Author | SHA1 | Date | |
|---|---|---|---|
| 823a284fbc | |||
| 67e601d0c4 | |||
| 7e4ebd91ad | |||
| 4dc5dee2b9 |
@@ -111,11 +111,13 @@ class HomeController extends Controller
|
||||
*/
|
||||
public function updateLanguage(Request $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if(! in_array($request->language, config('lang-detector.languages'))) {
|
||||
return redirect()->back();
|
||||
}
|
||||
abort_unless(in_array($request->language, config('app.supported_locales'), true), 404);
|
||||
|
||||
Cookie::queue(Cookie::forever('locale', $request->language));
|
||||
session(['locale' => $request->language]);
|
||||
|
||||
if (Auth::check()) {
|
||||
Auth::user()->update(['locale' => $request->language]);
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class Kernel extends HttpKernel
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\IsBanned::class,
|
||||
\App\Http\Middleware\SetLocale::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
||||
41
app/Http/Middleware/SetLocale.php
Normal file
41
app/Http/Middleware/SetLocale.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SetLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
// 1. Logged-in user preference
|
||||
if (Auth::check() && Auth::user()->locale) {
|
||||
App::setLocale(Auth::user()->locale);
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// 2. Session (guest or user override)
|
||||
if (session()->has('locale') && in_array($request->language, config('app.supported_locales'), true)) {
|
||||
App::setLocale(session('locale'));
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// 3. Browser language
|
||||
$locale = $request->getPreferredLanguage(config('app.supported_locales'));
|
||||
|
||||
if ($locale) {
|
||||
App::setLocale($locale);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ class EpisodeService
|
||||
Request $request,
|
||||
Hentai $hentai,
|
||||
int $episodeNumber,
|
||||
Studios $studio = null,
|
||||
Episode $referenceEpisode = null
|
||||
?Studios $studio = null,
|
||||
?Episode $referenceEpisode = null
|
||||
): Episode
|
||||
{
|
||||
$episode = new Episode();
|
||||
|
||||
@@ -12,27 +12,26 @@
|
||||
"guzzlehttp/guzzle": "^7.8.1",
|
||||
"hisorange/browser-detect": "^5.0",
|
||||
"http-interop/http-factory-guzzle": "^1.2",
|
||||
"intervention/image": "^3.9",
|
||||
"intervention/image-laravel": "^1.3",
|
||||
"laravel/framework": "^11.0",
|
||||
"laravel/sanctum": "^4.0",
|
||||
"intervention/image": "^3.11",
|
||||
"intervention/image-laravel": "^1.5",
|
||||
"laravel/framework": "^12.0",
|
||||
"laravel/sanctum": "^4.2",
|
||||
"laravel/scout": "^10.20",
|
||||
"laravel/socialite": "^5.24",
|
||||
"laravel/tinker": "^2.10",
|
||||
"livewire/livewire": "^3.6.4",
|
||||
"livewire/livewire": "^3.7.0",
|
||||
"maize-tech/laravel-markable": "^2.3.0",
|
||||
"meilisearch/meilisearch-php": "^1.16",
|
||||
"mews/captcha": "3.4.4",
|
||||
"mews/captcha": "^3.4.4",
|
||||
"predis/predis": "^2.2",
|
||||
"realrashid/sweet-alert": "^7.2",
|
||||
"rtconner/laravel-tagging": "^4.1",
|
||||
"rtconner/laravel-tagging": "^5.0",
|
||||
"socialiteproviders/discord": "^4.2",
|
||||
"spatie/laravel-discord-alerts": "^1.5",
|
||||
"spatie/laravel-sitemap": "^7.3",
|
||||
"vluzrmos/language-detector": "^2.3"
|
||||
"spatie/laravel-discord-alerts": "^1.8",
|
||||
"spatie/laravel-sitemap": "^7.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.14.7",
|
||||
"barryvdh/laravel-debugbar": "^3.16",
|
||||
"fakerphp/faker": "^1.24.0",
|
||||
"laravel/breeze": "^2.3",
|
||||
"laravel/pint": "^1.18",
|
||||
|
||||
1752
composer.lock
generated
1752
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -111,6 +111,18 @@ return [
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Supported Locales
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is used to display the supported locales by this app, it also is
|
||||
| used to verify session data and requests in the SetLocale Middleware
|
||||
|
|
||||
*/
|
||||
|
||||
'supported_locales' => ['en', 'de', 'fr'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
* Indicates whenever should autodetect and apply the language of the request.
|
||||
*/
|
||||
'autodetect' => env('LANG_DETECTOR_AUTODETECT', true),
|
||||
|
||||
/*
|
||||
* Default driver to use to detect the request language.
|
||||
*
|
||||
* Available: browser, subdomain, uri.
|
||||
*/
|
||||
'driver' => env('LANG_DETECTOR_DRIVER', 'browser'),
|
||||
|
||||
/*
|
||||
* Used on subdomain and uri drivers. That indicates which segment should be used
|
||||
* to verify the language.
|
||||
*/
|
||||
'segment' => env('LANG_DETECTOR_SEGMENT', 0),
|
||||
|
||||
/*
|
||||
* Languages available on the application.
|
||||
*
|
||||
* You could use parse_langs_to_array to use the string syntax
|
||||
* or just use the array of languages with its aliases.
|
||||
*/
|
||||
'languages' => parse_langs_to_array(
|
||||
env('LANG_DETECTOR_LANGUAGES', ['en', 'de', 'fr'])
|
||||
),
|
||||
|
||||
/*
|
||||
* Indicates if should store detected locale on cookies
|
||||
*/
|
||||
'cookie' => (bool) env('LANG_DETECTOR_COOKIE', true),
|
||||
|
||||
/*
|
||||
* Indicates if should encrypt cookie
|
||||
*/
|
||||
'cookie_encrypt' => (bool) env('LANG_DETECTOR_COOKIE_ENCRYPT', false),
|
||||
|
||||
/*
|
||||
* Cookie name
|
||||
*/
|
||||
'cookie_name' => env('LANG_DETECTOR_COOKIE', 'locale'),
|
||||
];
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('locale', 10)
|
||||
->nullable()
|
||||
->after('discord_avatar');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('locale');
|
||||
});
|
||||
}
|
||||
};
|
||||
1301
package-lock.json
generated
1301
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user