Php 单击表中的行时,打开包含数据的模式

Php 单击表中的行时,打开包含数据的模式,php,laravel,bootstrap-modal,laravel-livewire,Php,Laravel,Bootstrap Modal,Laravel Livewire,我正在通过laravel 8和livewire开发一个应用程序 我有一个名为dashboard.blade.php的视图,在这个视图中我有一个名为table collaboratori的livewire组件。 在我的表collaboratori.blade.php中,我添加了一个事件,它可以工作,事实上,从我的组件表collaboratori.php中,我可以正确地恢复我需要的数据。 我的疑问是,一旦数据恢复,我是否能够自动打开模式并将数据传递给它。 你对哪种方式最好有什么建议吗 这是我的代码:

我正在通过laravel 8和livewire开发一个应用程序

我有一个名为
dashboard.blade.php
的视图,在这个视图中我有一个名为
table collaboratori
的livewire组件。 在我的
表collaboratori.blade.php
中,我添加了一个事件,它可以工作,事实上,从我的组件
表collaboratori.php
中,我可以正确地恢复我需要的数据。 我的疑问是,一旦数据恢复,我是否能够自动打开模式并将数据传递给它。 你对哪种方式最好有什么建议吗

这是我的代码: LIVEWIRE组件:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Livewire\WithPagination;
use App\Tenant;
use App\Models\User;

class TableCollaboratori extends Component
{
    protected $paginationTheme = 'bootstrap';

    protected $connection = null;
    public $first_render = true;
    public $soggetti = null;
    public $users = null;
    public $idt = null;
    // variabile che associamo al singolo utente;
    public $user = null;

    public function mount(Request $request)
    {
        
        // Setto la connessione
        if (null !== $request->get('throughMiddleware')) {
            $this->connection = 'tenant';
        } else {
            //recupero l'id del tenant
            $this->connection = null;
            $this->idt = tenant('id');
        }

        //recupero la lista dei collaboratori del tenant
        $this->users = User::on($this->connection)->get();

    }

    public function openModal(Request $request, $id){
        
        // Setto la connessione
        if (null !== $request->get('throughMiddleware')) {
            $this->connection = 'tenant';
        } else {
            //recupero l'id del tenant
            $this->connection = null;
            $this->idt = tenant('id');
        }

        //recupero lo specifico utente
        $this->user = User::on($this->connection)->find($id);
        
        // HERE I NEED TO PASS DATA & OPEN THE MODAL UtenteLongModal 

    }

    public function render()
    {
        return view('livewire.table-collaboratori')
        ->with('idt', $this->idt)
        ->with('users', $this->users);
    }

}

这里是我的
表collaboratori.blade.php

<tbody>
    <tr>
        @foreach ($users as $u)
    <tr wire:click='openModal({{ $u->id }})'>
        <td>{{ $u->username }}</td>
        <td>{{ $u->nome }}</td>
        <td>{{ $u->cognome }}</td>
        <td>{{ $u->email }}</td>
        <td>{{ $u->codicefiscale }}</td>
        <td>{{ $u->abilitato }}</td>
        <td>{{ $u->id_qualifica }}</td>
        <td>
            <div class="d-flex">
                <a href="{{ url('tenants/' . $idt . '/users/'.$u->id.'/update') }}" class="btn btn-primary shadow btn-xs sharp mr-1" >
                    <i class="fa fa-pencil"></i></a>
                <form method="POST"
                    action="{{ url('tenants/' . $idt . '/users/impersonate') }}">
                    @csrf
                    <input type="hidden" value="{{ $u->id }}" name="idu">
                    <button type="submit" class="btn btn-success shadow btn-xs sharp">
                        <i class="fa fa-user-circle-o" aria-hidden="true"></i>
                    </button>
                </form>
                <form method="POST" action="{{ url('tenants/' . $idt . '/users/delete') }}">
                    @csrf
                    @method('delete')
                    <input type="hidden" value="{{ $u->id }}" name="idu">
                    <button type="submit" class="btn btn-danger shadow btn-xs sharp">
                        <i class="fa fa-trash"></i>
                    </button>
                </form>

            </div>
        </td>
    </tr>
    @endforeach
</tbody>


@foreach(用户为$u)
{{$u->username}
{{$u->nome}
{{$u->cognome}
{{$u->email}
{{$u->codicefiscale}
{{$u->abilitato}
{{$u->id_qualifica}
@csrf
@csrf
@方法('delete')
@endforeach
类似这样的东西

public $name;
public $email;
//.....

public function getModel($modelId)
{
   $model = Model::find($modelId);
   $this->name = $model->name;
   $this->email = $model->email;
   //...... this way you bind model data to properties
}

public function clickOpenModal($modelId)
{
   $this->getModel($modelId);
   $this->dispatchBrowserEvent('openModal');
}
在blade中的模型中,请记住将属性绑定到元素

// Table row
<.... wire:click="clickOpenModal({{ $item->id }})">

//  Model
<input class="" wire:model="name">
//....
//表行
//模型
//....

我认为您可以很好地管理collaboratori表中的模态ifblade@Prospero谢谢,如果我把模态代码放在blade table collaboratori中,我可以用哪种方式传递数据?因为我需要在组件呈现之后打开一个模式,并在单击组件Thank@Prospero生成的表上的一行之后,我使用livewire emit事件解决了这个问题,并且在页面末尾用JS填充了这个模式:-)听到这个消息很好。很好,我的朋友
// Table row
<.... wire:click="clickOpenModal({{ $item->id }})">

//  Model
<input class="" wire:model="name">
//....