From 517ca4e10a5a90228bd496b9a33e32f64893c9c0 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 19 Dec 2023 12:08:52 +0000 Subject: [PATCH 1/3] Fixes model route binding with custom keys --- src/VoltManager.php | 1 + tests/Feature/FunctionalComponentTest.php | 37 +++++++++++++++++++ .../with-model-route-binding.blade.php | 17 +++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/Feature/resources/views/functional-api/navigate/with-model-route-binding.blade.php diff --git a/src/VoltManager.php b/src/VoltManager.php index b7bcb21..5b51a5f 100644 --- a/src/VoltManager.php +++ b/src/VoltManager.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Artisan; use Livewire\Features\SupportTesting\Testable; use Livewire\Livewire; +use Livewire\Features\SupportPageComponents\SupportPageComponents; class VoltManager { diff --git a/tests/Feature/FunctionalComponentTest.php b/tests/Feature/FunctionalComponentTest.php index e5e0a7c..b580a8d 100644 --- a/tests/Feature/FunctionalComponentTest.php +++ b/tests/Feature/FunctionalComponentTest.php @@ -835,6 +835,43 @@ public function render() ->assertOk(); }); +it('test 200s model route binding on full page components', function (string $route, string $uri) { + User::create([ + 'name' => 'taylor', + 'email' => 'taylor@laravel.com', + 'password' => 'password', + ]); + + Volt::route('/users/'.$route, 'navigate.with-model-route-binding'); + + $this->get('/users/'.$uri) + ->assertStatus(200) + ->assertSee('Volt 1 using mount.'); +})->with([ + ['{user}', '1'], + ['{user:id}', '1'], + ['{user:name}', 'taylor'], + ['{user:email}', 'taylor@laravel.com'], +]); + +it('test 404s model route binding on full page components', function (string $route, string $uri) { + User::create([ + 'name' => 'taylor', + 'email' => 'taylor@laravel.com', + 'password' => 'password', + ]); + + Volt::route('/users/'.$route, 'navigate.with-model-route-binding'); + + $this->get('/users/'.$uri) + ->assertStatus(404); +})->with([ + ['{user}', '2'], + ['{user:id}', '2'], + ['{user:name}', 'nuno'], + ['{user:email}', 'nuno@laravel.com'], +]); + test('user imports on bottom do not conflict', function () { User::create([ 'name' => 'Taylor', diff --git a/tests/Feature/resources/views/functional-api/navigate/with-model-route-binding.blade.php b/tests/Feature/resources/views/functional-api/navigate/with-model-route-binding.blade.php new file mode 100644 index 0000000..8a2cd82 --- /dev/null +++ b/tests/Feature/resources/views/functional-api/navigate/with-model-route-binding.blade.php @@ -0,0 +1,17 @@ + $this->user = $user); + +?> + +
+
+ Volt {{ $user->id }} using mount. +
+
From 327d522f1d5a06f9197c97ddba185d057585b4ea Mon Sep 17 00:00:00 2001 From: nunomaduro Date: Tue, 19 Dec 2023 12:09:22 +0000 Subject: [PATCH 2/3] Fix code styling --- functions.php | 2 +- src/CompileContext.php | 2 +- src/FragmentAlias.php | 4 ++-- src/Options/StateOptions.php | 2 +- src/Options/UsesOptions.php | 2 +- src/VoltManager.php | 3 +-- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/functions.php b/functions.php index 6c55272..77b6c21 100644 --- a/functions.php +++ b/functions.php @@ -295,7 +295,7 @@ function usesFileUploads(): UsesOptions /** * Indicate that the component supports pagination. */ -function usesPagination(string $view = null, string $theme = null): UsesOptions +function usesPagination(?string $view = null, ?string $theme = null): UsesOptions { return (new UsesOptions)->usesPagination($view, $theme); } diff --git a/src/CompileContext.php b/src/CompileContext.php index 8095f37..f81855f 100644 --- a/src/CompileContext.php +++ b/src/CompileContext.php @@ -108,7 +108,7 @@ public function resolveListeners(Component $component): array /** * Register an event listener on the context. */ - public function listen(Closure|array|string $listenersOrEventName, Closure|string $handler = null): void + public function listen(Closure|array|string $listenersOrEventName, Closure|string|null $handler = null): void { if (is_array($listenersOrEventName)) { $listeners = $this->registerInlineListeners($listenersOrEventName); diff --git a/src/FragmentAlias.php b/src/FragmentAlias.php index 1836975..156191f 100644 --- a/src/FragmentAlias.php +++ b/src/FragmentAlias.php @@ -12,7 +12,7 @@ class FragmentAlias /** * Encode the given fragment's component name and path into a base64 embedded alias. */ - public static function encode(string $componentName, string $path, string $basePath = null): string + public static function encode(string $componentName, string $path, ?string $basePath = null): string { $basePath = $basePath ?? static::$basePath ?? base_path(); @@ -25,7 +25,7 @@ public static function encode(string $componentName, string $path, string $baseP /** * Resolve the given fragment's component name and path from a base64 embedded alias. */ - public static function decode(string $alias, string $basePath = null): ?array + public static function decode(string $alias, ?string $basePath = null): ?array { if (! static::isFragment($alias)) { return null; diff --git a/src/Options/StateOptions.php b/src/Options/StateOptions.php index 61efe33..9e880fc 100644 --- a/src/Options/StateOptions.php +++ b/src/Options/StateOptions.php @@ -70,7 +70,7 @@ public function reactive(): static /** * Indicate the state should be tracked in the URL. */ - public function url(string $as = null, bool $history = null, bool $keep = null): static + public function url(?string $as = null, ?bool $history = null, ?bool $keep = null): static { return $this->attribute(Url::class, as: $as, history: $history, keep: $keep); } diff --git a/src/Options/UsesOptions.php b/src/Options/UsesOptions.php index fa11db5..d37821b 100644 --- a/src/Options/UsesOptions.php +++ b/src/Options/UsesOptions.php @@ -21,7 +21,7 @@ public function usesFileUploads(): static /** * Indicate that the component should be compiled with pagination support. */ - public function usesPagination(string $view = null, string $theme = null): static + public function usesPagination(?string $view = null, ?string $theme = null): static { CompileContext::instance()->paginationView = $view; CompileContext::instance()->paginationTheme = $theme; diff --git a/src/VoltManager.php b/src/VoltManager.php index 5b51a5f..74430cc 100644 --- a/src/VoltManager.php +++ b/src/VoltManager.php @@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Artisan; use Livewire\Features\SupportTesting\Testable; use Livewire\Livewire; -use Livewire\Features\SupportPageComponents\SupportPageComponents; class VoltManager { @@ -90,7 +89,7 @@ public function withQueryParams(array $params): static /** * Set the currently logged in user for the application. */ - public function actingAs(Authenticatable $user, string $driver = null): static + public function actingAs(Authenticatable $user, ?string $driver = null): static { $this->manager->actingAs($user, $driver); From a32e987204ad3036c81d2a19e0c05087a6110ec1 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 27 Dec 2023 11:31:37 +0000 Subject: [PATCH 3/3] Uses Laravel Framework 10.38.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 33488c7..7daef66 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^8.1", - "laravel/framework": "^10.27|^11.0", + "laravel/framework": "^10.38.2|^11.0", "livewire/livewire": "^3.0" }, "require-dev": {