亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel Livewire 組件偏移

Laravel Livewire 組件偏移

PHP
慕仙森 2022-10-14 16:05:48
Livewire我正在嘗試通過稱為內部組件的 laravel 控制器獲取一些技術人員數據。在某些情況下,控制器返回null是因為沒有相關技術人員。這是我渲染視圖的 livewire 組件:class TechniciansAssociated extends Component{    public function render()    {        $technicians = (new HomeController())->getTechnicians();        return view('livewire.dashboard.technicians-associated', [            'technicians' => $technicians,        ]);    }}這里從家庭控制器調用函數:public function getTechnicians(){    $customer_ids = json_decode(User::find(Auth::id())->userCustomers->customer_id,true);    $technicians_data = DB::connection('mysql')        -> select('SELECT distinct users.id, users.name, users.surname, users.lastname, users.email, users.cargo, users.photo           FROM users           INNER JOIN contractsproductsmulti AS cpm ON users.id = cpm.userId           INNER JOIN contractsproducts AS cp ON cp.id = cpm.contractproduct_id           INNER JOIN contracts AS cont ON cont.id = cp.idcontract           WHERE users.isActive = 1 AND cont.idCustomer IN (?)', $customer_ids        );    if (count($technicians_data) > 0){        return $technicians_data;    }    return null;}最后,當嘗試獲取渲染 livewire 視圖的主視圖時,我遇到了錯誤@section('content')<section id="dash-cust-info">    <div class="row p-t-30 p-b-30">        <div class="col-md-6">            <h4>Customer info</h4>        </div>        <div class="col-md-3">            <h4>Comm_1</h4>            <div class="card no-border no-margin">                @livewire('dashboard.commercials-associated')            </div>        </div>        <div class="col-md-3">            <h4>Comm_2</h4>            <div class="card no-border no-margin">                @livewire('dashboard.technicians-associated')            </div>        </div>    </div>....錯誤:Undefined offset: 1 (View: /......../resources/views/home.blade.php)
查看完整描述

2 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

我想這個答案為 livewire 中的此類問題提供了很好的解釋。把它留在這里,這樣以后遇到這種問題的人都會得到幫助。不客氣



查看完整回答
反對 回復 2022-10-14
?
慕娘9325324

TA貢獻1783條經驗 獲得超4個贊

好的,LiveWire 組件需要一個 HTML 元素才能在它自己的視圖上獲得結果。例如:


<div> //missed on my code

    @foreach($users as $user)

        {{$user->id}}

    @endforeach

</div>


查看完整回答
反對 回復 2022-10-14
  • 2 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號