Skip to content

Commit

Permalink
Fixes model route binding with custom keys
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Dec 19, 2023
1 parent acd4d54 commit 517ca4e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/VoltManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Facades\Artisan;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
use Livewire\Features\SupportPageComponents\SupportPageComponents;

class VoltManager
{
Expand Down
37 changes: 37 additions & 0 deletions tests/Feature/FunctionalComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]',
'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}', '[email protected]'],
]);

it('test 404s model route binding on full page components', function (string $route, string $uri) {
User::create([
'name' => 'taylor',
'email' => '[email protected]',
'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}', '[email protected]'],
]);

test('user imports on bottom do not conflict', function () {
User::create([
'name' => 'Taylor',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
use function Livewire\Volt\mount;
use function Livewire\Volt\state;
use Tests\Fixtures\User;
state('user');
mount(fn (User $user) => $this->user = $user);
?>

<div>
<div>
Volt {{ $user->id }} using mount.
</div>
</div>

0 comments on commit 517ca4e

Please sign in to comment.