mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-06-05 15:07:42 +09:00
Task 3 - multi-level relationships
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -29,4 +30,22 @@ class RelationshipsTest extends TestCase
|
||||
$response = $this->get('/tasks');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
// TASK: define the two-level relationship in the User model
|
||||
public function test_show_users_comments()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$task = Task::create([
|
||||
'users_id' => $user->id,
|
||||
'name' => 'Some task'
|
||||
]);
|
||||
Comment::create([
|
||||
'task_id' => $task->id,
|
||||
'name' => 'Some name',
|
||||
'comment' => 'Some comment'
|
||||
]);
|
||||
|
||||
$response = $this->get('/users/' . $user->id);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user