Support the ongoing development of Laravel.io →
posted 3 years ago
Laravel

Hi , im learning livewire so just write this test :

/**
     * @test
     */
    public function if_a_wrong_query_string_has_been_set_no_data_should_be_returned()
    {
        Livewire::withQueryParams(['post_id',rand()])
            ->test('posts')
            ->assertSee('title','')
            ->assertSee('text','')
            ->assertSee('save');
    }

this test returns green! .. but in action this error comes up :

No query results for model [App\Models\Post] 444 (View: E:\---\livewire_CRUD\resources\views\welcome.blade.php)

I have implemented mount() in component like so :

public $posts, $post, $title, $text, $post_id;
protected $queryString = ['post_id'];

public function mount()
    {
        if ($this->post_id) {
            $this->queryString['post_id'] = $this->post_id;
            $this->edit($this->queryString['post_id']);
        }
    }

and edit method is :

public function edit($post_id)
    {
        $post = Post::findOrFail($post_id);
        $this->editPost = true;
        $this->title = $post->title;
        $this->text = $post->text;
        $this->post_id = $post->id;
        $this->resetErrorBag();
    }
Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

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.