Livewire 视图未在记录创建时更新

Livewire view not updatding on record create

我这辈子都解决不了这个问题

我的 blade 文件中有一个列表,如下所示:

@foreach($interactions as $interaction)
                <div class="border rounded px-2 my-2 op-gray w-100">
                    <div class="d-flex flex-justify-between">
                        <div>
                            <b class="fg-steel">{{$interaction->user->name ?? 'Usuario No Existente'}}</b>
                            <small class="">{{$interaction->created_at}}</small>
                        </div>
                        <span class="fg-steel">{{$interaction->InteractionType->type_name}} <small class="fg-green p-1 rounded">{{$interaction->InteractionType->status_name}}</small></span>
                    </div>
                    <div>
                        {{$interaction->body}}
                    </div>
                </div>
@endforeach

但是,当添加新的 $interaction 时,不会 DOM 更新,直到第二个 $interaction 被更新。 (第一次互动更新)。

<?php

namespace App\Http\Livewire\Client\Details;

use App\Models\Interaction;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class NewInteraction extends Component
{
    public $grouped_interactions;
    public $client;

    public $interaction = [];
//    public $interactions;
//    public $pending_item = [];
    public $pending_items = [];
//    public $appointment = [];
    public $appointments = [];
    public $contacts = [];

    protected $rules = [
        'interaction.type'          =>  ''
    ];

    public function render()
    {
        $interactions = $this->client->interactions;
        return view('livewire.client.details.new-interaction', compact('interactions'));
    }

    public function createNewInteraction() {

        Interaction::create([
            'interaction_type_id'       =>  $this->interaction['type'],
            'body'                      =>  $this->interaction['body'],
            'client_id'                 =>  $this->client->id,
            'user_id'                   =>  Auth::user()->id,
                            ]);

        $this->interaction['type'] = "";
        $this->interaction['body'] = "";

    }
}

我做错了什么?

好的,以防万一有人发现这个问题(因为我没有在网上找到很多资源)。

问题是因为记录是通过关系插入的,因此 Livewire 不知道有什么改变。

做一个 model->refresh() 解决了问题...