shez1983's avatar

updating search results, get part of previous result with new result

what happens is, when i click on a category to show related posts, it works initially (fresh page load) - but on subsequent click on a different category, if there are 3 results, 2 of them will be related to NEW cat, the third one will be of the previous category.

i use <a wire:click=method(id)>cat</a> to send cat type to component, re-run the search (which is a lot more convulated than a simple, post::whereType..

the QUERY is actually working.. this is my log statements for initial load, u can see collection id [9] ONE result which is totally FINE

mount  
render  
search  
typeid [2] 
comp count [{"Illuminate\\Support\\Collection":[9]}] 

then when i click on a diff category you can see 6,7,8

updatType  
render  
search  
typeid [1] 
comp count [{"Illuminate\\Support\\Collection":[6,7,8]}] 

but on the page i see Ids/models : 9, 7, 8, i am doing a

foreach($posts as $post)  {
	dump($post->id). // HERE corect IDs will be dumped eg 6, 7, 8

   <sub component :post=$post> //inside here if i then do $post->id, i will see 9, 7,8
}

HERE is my component:

here is my view:

<div class="index">
    <div class="filter">
        <p>Please choose what you are looking for</p>
        <div class="types">
            {{  $this->type }}
            @foreach($types as $type)
                <div class="type">
                    <a style="cursor: pointer"
                        wire:click="updateType({{  $type->id }})"
                        {{-- href="{{ route('posts.index', ['type' => $type->slug]) }}" --}}
                    >
                        <img src="{{ asset($type->image) }}"/>
                        {{  $type->name }}
                    </a>
                </div>
            @endforeach
        </div>
    </div>

    <div class="posts">
        @foreach ($posts as $post)
            @dump($post->id)
            <livewire:posts.card  :post="$post"/>
        @endforeach
    </div>
</div>

here is the post card: (child)

<div class="post">
    <img src="{{ asset($post->image) }}"/>
    {{ $post->name }}<br/>
    {{ $post->id }}<br/>
</div>
0 likes
1 reply

Please or to participate in this conversation.