diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 45bd3bbc..43240e02 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace BlumilkWebsite\Console; +namespace Blumilk\Website\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 36065e50..51de315c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace BlumilkWebsite\Exceptions; +namespace Blumilk\Website\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php new file mode 100644 index 00000000..9bae09e1 --- /dev/null +++ b/app/Http/Controllers/ContactController.php @@ -0,0 +1,16 @@ +render("Contact"); + } +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 6aef5e56..551eadab 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace BlumilkWebsite\Http\Controllers; +namespace Blumilk\Website\Http\Controllers; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; diff --git a/app/Http/Controllers/FallbackController.php b/app/Http/Controllers/FallbackController.php new file mode 100644 index 00000000..157f576a --- /dev/null +++ b/app/Http/Controllers/FallbackController.php @@ -0,0 +1,47 @@ +shouldRedirect()) { + return false; + } + + $localizedUrl = Route::localizedUrl(); + $route = $this->findRouteByUrl($localizedUrl); + + if ($route->isFallback) { + return false; + } + + return Redirect::to($route->uri(), $this->getRedirectStatusCode()) + ->header("Cache-Control", "no-store, no-cache, must-revalidate"); + } + + protected function findRouteByUrl(string $url): \Illuminate\Routing\Route + { + $parts = explode("/", $url); + $path = implode("/", array_splice($parts, 4)); + $url = $this->translator->uri($path); + + $domain = implode("/", array_splice($parts, -4)); + + return Route::getRoutes()->match(Request::create($domain . "/" . $url)); + } +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 00000000..ce7eb266 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,16 @@ +render("Home"); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d3132f79..edd5b618 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,36 +2,39 @@ declare(strict_types=1); -namespace BlumilkWebsite\Http; +namespace Blumilk\Website\Http; -use BlumilkWebsite\Http\Middleware\Authenticate; -use BlumilkWebsite\Http\Middleware\EncryptCookies; -use BlumilkWebsite\Http\Middleware\HandleInertiaRequests; -use BlumilkWebsite\Http\Middleware\PreventRequestsDuringMaintenance; -use BlumilkWebsite\Http\Middleware\RedirectIfAuthenticated; -use BlumilkWebsite\Http\Middleware\TrimStrings; -use BlumilkWebsite\Http\Middleware\TrustProxies; -use BlumilkWebsite\Http\Middleware\ValidateSignature; -use BlumilkWebsite\Http\Middleware\VerifyCsrfToken; +use Blumilk\Website\Http\Middleware\Authenticate; +use Blumilk\Website\Http\Middleware\Localize; +use Blumilk\Website\Http\Middleware\RedirectIfAuthenticated; +use Blumilk\Website\Http\Middleware\TrimStrings; +use Blumilk\Website\Http\Middleware\TrustProxies; +use CodeZero\LocalizedRoutes\Middleware\SetLocale; use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth; use Illuminate\Auth\Middleware\Authorize; use Illuminate\Auth\Middleware\EnsureEmailIsVerified; use Illuminate\Auth\Middleware\RequirePassword; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; +use Illuminate\Cookie\Middleware\EncryptCookies; use Illuminate\Foundation\Http\Kernel as HttpKernel; use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull; +use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance; use Illuminate\Foundation\Http\Middleware\ValidatePostSize; +use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; use Illuminate\Http\Middleware\HandleCors; use Illuminate\Http\Middleware\SetCacheHeaders; use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Routing\Middleware\ThrottleRequests; +use Illuminate\Routing\Middleware\ValidateSignature; use Illuminate\Session\Middleware\AuthenticateSession; use Illuminate\Session\Middleware\StartSession; use Illuminate\View\Middleware\ShareErrorsFromSession; +use Inertia\Middleware as HandleInertiaRequests; class Kernel extends HttpKernel { protected $middleware = [ + Localize::class, TrustProxies::class, HandleCors::class, PreventRequestsDuringMaintenance::class, @@ -46,6 +49,7 @@ class Kernel extends HttpKernel StartSession::class, ShareErrorsFromSession::class, VerifyCsrfToken::class, + SetLocale::class, SubstituteBindings::class, HandleInertiaRequests::class, ], diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 1124767c..e08cf789 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace BlumilkWebsite\Http\Middleware; +namespace Blumilk\Website\Http\Middleware; use Illuminate\Auth\Middleware\Authenticate as Middleware; use Illuminate\Http\Request; diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php deleted file mode 100644 index 5d8f4eb4..00000000 --- a/app/Http/Middleware/EncryptCookies.php +++ /dev/null @@ -1,12 +0,0 @@ -header("Accept-Language"), "pl")) { + app()->setLocale("pl"); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php deleted file mode 100644 index 7a0ec8c3..00000000 --- a/app/Http/Middleware/PreventRequestsDuringMaintenance.php +++ /dev/null @@ -1,13 +0,0 @@ -prefix("api") ->group(base_path("routes/api.php")); - Route::middleware("web") - ->group(base_path("routes/web.php")); + Route::localized(function (): void { + Route::middleware("web") + ->group(base_path("routes/web.php")); + }); + + Route::fallback(FallbackController::class); }); } } diff --git a/bootstrap/app.php b/bootstrap/app.php index a34893be..008284e0 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -2,9 +2,9 @@ declare(strict_types=1); -use BlumilkWebsite\Console\Kernel as ConsoleKernel; -use BlumilkWebsite\Exceptions\Handler; -use BlumilkWebsite\Http\Kernel as HttpKernel; +use Blumilk\Website\Console\Kernel as ConsoleKernel; +use Blumilk\Website\Exceptions\Handler; +use Blumilk\Website\Http\Kernel as HttpKernel; use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Http\Kernel as HttpKernelContract; diff --git a/composer.json b/composer.json index 68bc4a82..14b75a41 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.2", "ext-pdo": "*", + "codezero/laravel-localized-routes": "^3.1", "guzzlehttp/guzzle": "^7.8.0", "inertiajs/inertia-laravel": "^0.6.11", "laravel/framework": "^10.32.1", @@ -24,7 +25,7 @@ }, "autoload": { "psr-4": { - "BlumilkWebsite\\": "app/", + "Blumilk\\Website\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } @@ -66,7 +67,8 @@ "preferred-install": "dist", "sort-packages": true, "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": true, + "codezero/composer-preload-files": true } }, "minimum-stability": "stable", diff --git a/composer.lock b/composer.lock index be11bdec..8fd66fdb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "398810ea5ea540a05776ca8ad1c485f2", + "content-hash": "d2ee22e0186e116f54ea76abef028d54", "packages": [ { "name": "brick/math", @@ -130,6 +130,351 @@ ], "time": "2023-12-11T17:09:12+00:00" }, + { + "name": "codezero/browser-locale", + "version": "3.3.0", + "source": { + "type": "git", + "url": "https://github.com/codezero-be/browser-locale.git", + "reference": "5dc1b89c8dcaece285b2ebb69ebdc783144e4cab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codezero-be/browser-locale/zipball/5dc1b89c8dcaece285b2ebb69ebdc783144e4cab", + "reference": "5dc1b89c8dcaece285b2ebb69ebdc783144e4cab", + "shasum": "" + }, + "require": { + "php": "^7.0|^8.0" + }, + "require-dev": { + "illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0", + "mockery/mockery": "^1.3.3", + "phpunit/phpunit": "^6.0|^7.0|^8.0|^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "CodeZero\\BrowserLocale\\Laravel\\BrowserLocaleServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "CodeZero\\BrowserLocale\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Vermeyen", + "email": "ivan@codezero.be" + } + ], + "description": "Get the most preferred locales from your visitor's browser.", + "keywords": [ + "browser", + "country", + "detect", + "language", + "locale", + "php", + "website" + ], + "support": { + "issues": "https://github.com/codezero-be/browser-locale/issues", + "source": "https://github.com/codezero-be/browser-locale/tree/3.3.0" + }, + "funding": [ + { + "url": "https://paypal.me/ivanvermeyen", + "type": "custom" + }, + { + "url": "https://ko-fi.com/ivanvermeyen", + "type": "ko_fi" + } + ], + "time": "2023-02-03T13:33:21+00:00" + }, + { + "name": "codezero/composer-preload-files", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/codezero-be/composer-preload-files.git", + "reference": "83246aa68c08ed7c2b1dbcb451b4faf65aa658d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codezero-be/composer-preload-files/zipball/83246aa68c08ed7c2b1dbcb451b4faf65aa658d9", + "reference": "83246aa68c08ed7c2b1dbcb451b4faf65aa658d9", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": ">= 7.0" + }, + "require-dev": { + "composer/composer": "^2.0" + }, + "type": "composer-plugin", + "extra": { + "class": "CodeZero\\ComposerPreloadFiles\\Plugin" + }, + "autoload": { + "psr-4": { + "CodeZero\\ComposerPreloadFiles\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Vermeyen", + "email": "ivan@codezero.be" + } + ], + "description": "Composer plugin to autoload files before vendor files.", + "keywords": [ + "autoload", + "composer", + "files", + "helpers", + "include", + "load", + "plugin", + "require" + ], + "support": { + "issues": "https://github.com/codezero-be/composer-preload-files/issues", + "source": "https://github.com/codezero-be/composer-preload-files/tree/1.0.2" + }, + "time": "2023-05-24T15:46:41+00:00" + }, + { + "name": "codezero/laravel-localized-routes", + "version": "3.1.5", + "source": { + "type": "git", + "url": "https://github.com/codezero-be/laravel-localized-routes.git", + "reference": "0ebb3acd58b4b635ec9d6d20de9a1770da0c9ced" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codezero-be/laravel-localized-routes/zipball/0ebb3acd58b4b635ec9d6d20de9a1770da0c9ced", + "reference": "0ebb3acd58b4b635ec9d6d20de9a1770da0c9ced", + "shasum": "" + }, + "require": { + "codezero/browser-locale": "^3.0", + "codezero/composer-preload-files": "^1.0", + "codezero/laravel-uri-translator": "^1.0", + "codezero/php-url-builder": "^1.0", + "illuminate/support": "^7.0|^8.0|^9.0|^10.0", + "php": "^7.2.5|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0", + "phpunit/phpunit": "^8.0|^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "CodeZero\\LocalizedRoutes\\LocalizedRoutesServiceProvider" + ], + "aliases": { + "LocaleConfig": "CodeZero\\LocalizedRoutes\\Facades\\LocaleConfig" + } + }, + "preload-files": [ + "src/helpers.php" + ] + }, + "autoload": { + "psr-4": { + "CodeZero\\LocalizedRoutes\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Vermeyen", + "email": "ivan@codezero.be" + } + ], + "description": "A convenient way to set up, manage and use localized routes in a Laravel app.", + "keywords": [ + "country", + "language", + "laravel", + "locale", + "localization", + "php", + "routes", + "routing", + "translation" + ], + "support": { + "issues": "https://github.com/codezero-be/laravel-localized-routes/issues", + "source": "https://github.com/codezero-be/laravel-localized-routes/tree/3.1.5" + }, + "funding": [ + { + "url": "https://paypal.me/ivanvermeyen", + "type": "custom" + }, + { + "url": "https://ko-fi.com/ivanvermeyen", + "type": "ko_fi" + } + ], + "time": "2023-06-01T20:21:52+00:00" + }, + { + "name": "codezero/laravel-uri-translator", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/codezero-be/laravel-uri-translator.git", + "reference": "30e630dc89908e4075c650d8858d1630764b9540" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codezero-be/laravel-uri-translator/zipball/30e630dc89908e4075c650d8858d1630764b9540", + "reference": "30e630dc89908e4075c650d8858d1630764b9540", + "shasum": "" + }, + "require": { + "illuminate/support": "^7.0|^8.0|^9.0|^10.0", + "php": "^7.2.5|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0", + "phpunit/phpunit": "^8.0|^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "CodeZero\\UriTranslator\\UriTranslatorServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "CodeZero\\UriTranslator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Vermeyen", + "email": "ivan@codezero.be" + } + ], + "description": "Translate a URI or individual slugs.", + "keywords": [ + "country", + "language", + "laravel", + "locale", + "localization", + "php", + "slugs", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/codezero-be/laravel-uri-translator/issues", + "source": "https://github.com/codezero-be/laravel-uri-translator/tree/1.0.0" + }, + "funding": [ + { + "url": "https://paypal.me/ivanvermeyen", + "type": "custom" + }, + { + "url": "https://ko-fi.com/ivanvermeyen", + "type": "ko_fi" + } + ], + "time": "2023-03-14T15:01:53+00:00" + }, + { + "name": "codezero/php-url-builder", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/codezero-be/php-url-builder.git", + "reference": "c30a21c503158c26dd4ab5cfdf64b2eb90fa9f78" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codezero-be/php-url-builder/zipball/c30a21c503158c26dd4ab5cfdf64b2eb90fa9f78", + "reference": "c30a21c503158c26dd4ab5cfdf64b2eb90fa9f78", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.0|^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "CodeZero\\UrlBuilder\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Vermeyen", + "email": "ivan@codezero.be" + } + ], + "description": "Parse, manipulate and rebuild a URL.", + "keywords": [ + "builder", + "parse", + "query", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/codezero-be/php-url-builder/issues", + "source": "https://github.com/codezero-be/php-url-builder/tree/1.0.0" + }, + "funding": [ + { + "url": "https://paypal.me/ivanvermeyen", + "type": "custom" + }, + { + "url": "https://ko-fi.com/ivanvermeyen", + "type": "ko_fi" + } + ], + "time": "2023-03-31T17:50:16+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", diff --git a/config/app.php b/config/app.php index aacd3050..54b30cfc 100644 --- a/config/app.php +++ b/config/app.php @@ -2,9 +2,9 @@ declare(strict_types=1); -use BlumilkWebsite\Providers\AppServiceProvider; -use BlumilkWebsite\Providers\EventServiceProvider; -use BlumilkWebsite\Providers\RouteServiceProvider; +use Blumilk\Website\Providers\AppServiceProvider; +use Blumilk\Website\Providers\EventServiceProvider; +use Blumilk\Website\Providers\RouteServiceProvider; use Illuminate\Support\Facades\Facade; use Illuminate\Support\ServiceProvider; @@ -15,7 +15,7 @@ ])->toArray(); return [ - "name" => env("APP_NAME", "Laravel"), + "name" => "Blumilk software development", "env" => env("APP_ENV", "production"), "debug" => (bool)env("APP_DEBUG", false), "url" => env("APP_URL", "http://localhost"), diff --git a/config/auth.php b/config/auth.php index 7c58a286..7c4c12c9 100644 --- a/config/auth.php +++ b/config/auth.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use BlumilkWebsite\Models\User; +use Blumilk\Website\Models\User; return [ "defaults" => [ diff --git a/config/localized-routes.php b/config/localized-routes.php new file mode 100644 index 00000000..4f0f2906 --- /dev/null +++ b/config/localized-routes.php @@ -0,0 +1,47 @@ + ["en", "pl"], + "fallback_locale" => "en", + "omitted_locale" => null, + "redirect_to_localized_urls" => true, + "redirect_status_code" => 301, + "404_view" => "errors.404", + "route_action" => "locale", + "user_attribute" => "locale", + "session_key" => "locale", + "cookie_name" => "locale", + "cookie_minutes" => 60 * 24 * 365, + "detectors" => [ + RouteActionDetector::class, + UrlDetector::class, + OmittedLocaleDetector::class, + UserDetector::class, + SessionDetector::class, + CookieDetector::class, + BrowserDetector::class, + AppDetector::class, + ], + "trusted_detectors" => [ + RouteActionDetector::class, + ], + "stores" => [ + SessionStore::class, + CookieStore::class, + AppStore::class, + ], +]; diff --git a/config/sanctum.php b/config/sanctum.php index 7e51295a..df13425b 100644 --- a/config/sanctum.php +++ b/config/sanctum.php @@ -2,8 +2,8 @@ declare(strict_types=1); -use BlumilkWebsite\Http\Middleware\EncryptCookies; -use BlumilkWebsite\Http\Middleware\VerifyCsrfToken; +use Blumilk\Website\Http\Middleware\EncryptCookies; +use Blumilk\Website\Http\Middleware\VerifyCsrfToken; use Laravel\Sanctum\Sanctum; return [ diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 2ee4f682..2dc45536 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -4,7 +4,7 @@ namespace Database\Factories; -use BlumilkWebsite\Models\User; +use Blumilk\Website\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; diff --git a/environment/dev/app/Dockerfile b/environment/dev/app/Dockerfile index 10d43dff..775f9fda 100644 --- a/environment/dev/app/Dockerfile +++ b/environment/dev/app/Dockerfile @@ -5,7 +5,7 @@ FROM composer/composer:2.6.5-bin as composer-bin FROM node:21.1.0-bullseye-slim as node # For other versions check: https://hub.docker.com/_/php/tags?page=1&name=fpm-bullseye -FROM php:8.2.12-fpm-bullseye +FROM php:8.3.1-fpm-bullseye COPY --from=composer-bin ./composer /usr/bin/composer diff --git a/lang/pl/routes.php b/lang/pl/routes.php new file mode 100644 index 00000000..0c66ce1e --- /dev/null +++ b/lang/pl/routes.php @@ -0,0 +1,7 @@ + "kontakt", +]; diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100644 index e69de29b..00000000 diff --git a/public/logo.png b/public/logo.png new file mode 100644 index 00000000..c6124b40 Binary files /dev/null and b/public/logo.png differ diff --git a/resources/js/Layout/Navigation.vue b/resources/js/Layout/Navigation.vue new file mode 100644 index 00000000..5c4440b8 --- /dev/null +++ b/resources/js/Layout/Navigation.vue @@ -0,0 +1,10 @@ + + + diff --git a/resources/js/Pages/Contact.vue b/resources/js/Pages/Contact.vue new file mode 100644 index 00000000..27f3ec12 --- /dev/null +++ b/resources/js/Pages/Contact.vue @@ -0,0 +1,13 @@ + + + diff --git a/resources/js/Pages/Home.vue b/resources/js/Pages/Home.vue new file mode 100644 index 00000000..c926189b --- /dev/null +++ b/resources/js/Pages/Home.vue @@ -0,0 +1,13 @@ + + + diff --git a/resources/js/Pages/Welcome.vue b/resources/js/Pages/Welcome.vue deleted file mode 100644 index 4ebcef1a..00000000 --- a/resources/js/Pages/Welcome.vue +++ /dev/null @@ -1,286 +0,0 @@ - - - - - diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php index 9911d029..0d2fb68d 100644 --- a/resources/views/app.blade.php +++ b/resources/views/app.blade.php @@ -1,12 +1,28 @@ - + - - - @vite('resources/js/app.ts') + + + + + @vite("resources/js/app.ts") @inertiaHead -@inertia + @if (Route::isLocalized() || Route::isFallback()) + + @endif + + @inertia diff --git a/routes/web.php b/routes/web.php index 2301789d..120a2949 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,7 +2,14 @@ declare(strict_types=1); -use Illuminate\Support\Facades\Route; -use Inertia\Response; +use Blumilk\Website\Http\Controllers\ContactController; +use Blumilk\Website\Http\Controllers\HomeController; +use Illuminate\Routing\Router; +use Illuminate\Translation\Translator; -Route::get("/", fn(): Response => inertia("Welcome")); +/** @var Router $router */ +$router = app(Router::class); +$lang = app(Translator::class); + +$router->get("/", HomeController::class)->name("home"); +$router->get($lang->uri("contact"), ContactController::class)->name("contact"); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 55a42c3a..00000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,17 +0,0 @@ -get("/"); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/LocalisedRoutingFallbackTest.php b/tests/Feature/LocalisedRoutingFallbackTest.php new file mode 100644 index 00000000..54e03a9a --- /dev/null +++ b/tests/Feature/LocalisedRoutingFallbackTest.php @@ -0,0 +1,28 @@ +get("/contact"); + $response->assertStatus(301)->assertRedirect("/en/contact"); + } + + public function testFallbackLocaleForPolishRedirect(): void + { + $response = $this->get("/contact", ["Accept-Language" => "pl"]); + $response->assertStatus(301)->assertRedirect("/pl/kontakt"); + } + + public function testFallbackLocaleForNotSupportedLanguageRedirect(): void + { + $response = $this->get("/contact", ["Accept-Language" => "kz"]); + $response->assertStatus(301)->assertRedirect("/en/contact"); + } +} diff --git a/tests/Feature/LocalisedRoutingTest.php b/tests/Feature/LocalisedRoutingTest.php new file mode 100644 index 00000000..bf9ac616 --- /dev/null +++ b/tests/Feature/LocalisedRoutingTest.php @@ -0,0 +1,34 @@ +get("/en/contact"); + $response->assertStatus(200); + } + + public function testExistingLocalisedRoute(): void + { + $response = $this->get("/pl/kontakt"); + $response->assertStatus(200); + } + + public function testNonExistingRoute(): void + { + $response = $this->get("/en/kontakt"); + $response->assertStatus(404); + } + + public function testNonExistingLocalisedRoute(): void + { + $response = $this->get("/pl/contact"); + $response->assertStatus(404); + } +}