mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-07-11 18:56:11 +09:00
Task 5 - pivot with extra fields
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Role;
|
||||
use App\Models\Task;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -64,4 +65,23 @@ class RelationshipsTest extends TestCase
|
||||
$response = $this->get('/roles');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
// TASK: pivot table with extra fields
|
||||
public function test_teams_with_users()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$team = Team::create(['name' => 'Team 1']);
|
||||
$createdAt = now()->toDateTimeString();
|
||||
$position = 'Manager';
|
||||
DB::table('team_user')->insert([
|
||||
'team_id' => $team->id,
|
||||
'user_id' => $user->id,
|
||||
'position' => $position,
|
||||
'created_at' => $createdAt
|
||||
]);
|
||||
|
||||
$response = $this->get('/teams');
|
||||
$response->assertSee($createdAt);
|
||||
$response->assertSee($position);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user