Livewire我正在嘗試通過(guò)稱(chēng)為內(nèi)部組件的 laravel 控制器獲取一些技術(shù)人員數(shù)據(jù)。在某些情況下,控制器返回null是因?yàn)闆](méi)有相關(guān)技術(shù)人員。這是我渲染視圖的 livewire 組件:class TechniciansAssociated extends Component{ public function render() { $technicians = (new HomeController())->getTechnicians(); return view('livewire.dashboard.technicians-associated', [ 'technicians' => $technicians, ]); }}這里從家庭控制器調(diào)用函數(shù):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;}最后,當(dāng)嘗試獲取渲染 livewire 視圖的主視圖時(shí),我遇到了錯(cuò)誤@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>....錯(cuò)誤:Undefined offset: 1 (View: /......../resources/views/home.blade.php)
2 回答

夢(mèng)里花落0921
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊

慕娘9325324
TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊
好的,LiveWire 組件需要一個(gè) HTML 元素才能在它自己的視圖上獲得結(jié)果。例如:
<div> //missed on my code
@foreach($users as $user)
{{$user->id}}
@endforeach
</div>
- 2 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報(bào)
0/150
提交
取消