Need to test that you are passing the correct data to a view? You can use the viewData method on your response. Here are some examples:
/** @test */public function it_has_the_correct_value(){ // ... $response = $this->get('/some-route'); $this->assertEquals('John Doe', $response->viewData('name'));} /** @test */public function it_contains_a_given_record(){ // ... $response = $this->get('/some-route'); $this->assertTrue($response->viewData('users')->contains($userA));} /** @test */public function it_returns_the_correct_amount_of_records(){ // ... $response = $this->get('/some-route'); $this->assertCount(10, $response->viewData('users'));}
Tip given by @JuanRangelTX
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses on Laravel Daily
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
AI Agents/IDEs for Laravel: May 2026 (Claude Code, Codex, OpenCode, etc)
7 lessons
52 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read