create(['first_name' => 'Luke', 'last_name' => 'Skywalker']); User::factory()->create(['first_name' => 'Darth', 'last_name' => 'Vader']); $response = $this->actingAsForApi(User::factory()->viewUsers()->create()) ->getJson(route('api.users.index', ['search' => 'luke sky'])) ->assertOk(); $results = collect($response->json('rows')); $this->assertEquals(1, $results->count()); $this->assertTrue($results->pluck('name')->contains(fn($text) => str_contains($text, 'Luke'))); $this->assertFalse($results->pluck('name')->contains(fn($text) => str_contains($text, 'Darth'))); } }