create([ 'title' => 'Draft Case', 'sort_order' => 1, 'published_at' => null, ]); $second = PortfolioCase::factory()->published()->create([ 'title' => 'Second Case', 'sort_order' => 20, ]); $first = PortfolioCase::factory()->published()->create([ 'title' => 'First Case', 'sort_order' => 10, ]); PortfolioImage::query()->create([ 'portfolio_case_id' => $first->id, 'path' => 'content/first-a.jpg', 'alt_text' => 'First A', 'caption' => null, 'sort_order' => 1, ]); PortfolioImage::query()->create([ 'portfolio_case_id' => $first->id, 'path' => 'content/first-b.jpg', 'alt_text' => 'First B', 'caption' => null, 'sort_order' => 2, ]); $cases = (new GetPublishedPortfolioCases)(); $this->assertCount(2, $cases); $this->assertTrue($cases->get(0)?->is($first)); $this->assertTrue($cases->get(1)?->is($second)); $this->assertFalse($cases->contains(fn (PortfolioCase $case): bool => $case->title === 'Draft Case')); $this->assertTrue($cases->get(0)?->relationLoaded('images')); $this->assertCount(2, $cases->get(0)?->images ?? []); } }