Support the ongoing development of Laravel.io →
Breeze Vue.js Laravel

I am sending data along with a vue in Laravel 9 with Inertia Vue 3 app. Here is the code in controller function.

public function index() {
    $sliders = Slider::all();
    return Inertia::render('Admin/Slider/Index', [ 'sliders' => $sliders]);
  }

Inside the test file, I am testing if $sliders count is equal. Check the following code:

public function test_render_slider_management_view_has_all_sliders() {

    $user = User::factory()->create(['role' => 1]);
    $random_sliders = Slider::factory()->count(5)->create();
    $response = $this->actingAs($user)->get(app()->getLocale().'/admin/sliders');

    $response->assertViewHas('sliders', function ($sliders) {
      return count((array)$sliders) == 5;
    });
  }

This test gives a generic error of Failed asserting that false is true.. Upon checking $sliders variable in the closure, its value is null.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.