-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Fixes index views on nested model route bindings (#108)
* Fixes index views on nested model route bindings * Updates test
- Loading branch information
1 parent
0e353c3
commit 765b765
Showing
6 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Fixtures; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Movie extends Model | ||
{ | ||
protected $table = 'movies'; | ||
|
||
protected $guarded = []; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class, 'user_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,23 @@ | |
use Laravel\Folio\Pipeline\PotentiallyBindablePathSegment; | ||
use Tests\Feature\Fixtures\Event; | ||
use Tests\Feature\Fixtures\Podcast; | ||
use Tests\Feature\Fixtures\User; | ||
|
||
beforeEach(function () { | ||
Schema::create('users', function ($table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::create('movies', function ($table) { | ||
$table->id(); | ||
$table->foreignId('user_id'); | ||
$table->string('name'); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::create('podcasts', function ($table) { | ||
$table->id(); | ||
$table->string('name'); | ||
|
@@ -79,6 +94,25 @@ | |
$this->get('/podcasts/missing-id')->assertNotFound(); | ||
}); | ||
|
||
test('child implicit bindings are resolved', function () { | ||
$user = User::create([ | ||
'name' => 'test-name', | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$user->movies()->create([ | ||
'name' => 'test-movie-name', | ||
]); | ||
|
||
$movie = $user->movies()->create([ | ||
'name' => 'test-movie-name-2', | ||
]); | ||
|
||
$this->get('/users/movies/'.$user->id.'/'.$movie->id)->assertSee( | ||
'test-name: test-movie-name-2.', | ||
); | ||
}); | ||
|
||
test('child implicit bindings are scoped to the parent if field is present', function () { | ||
$podcast = Podcast::create([ | ||
'name' => 'test-podcast-name', | ||
|
3 changes: 3 additions & 0 deletions
3
...ers/movies/[.Tests.Feature.Fixtures.User]/[.Tests.Feature.Fixtures.Movie]/index.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
{{ $user->name }}: {{ $movie->name }}. | ||
</div> |