我将laravel 5.6与mongodb 4.0一起使用,当我得到结果时,它显示“正在尝试获取非对象的属性”,我的代码有什么问题?
我的控制器
$word = $request->get('q');
$page = \Illuminate\Pagination\Paginator::resolveCurrentPage();
$perPage = 20;
$hitung_baris = Dapil_Kotakab::whereRaw(array('$text'=>array('$search'=> "\"".$word."\"" )))->get();
$total = $hitung_baris->count();
$collection = Dapil_Kotakab::raw(function ($collection) use ($word, $page, $perPage){
array('$text'=>array('$search'=> "\"".$word."\"" ));
return $collection->aggregate([
[
'$lookup' => [
'as' => 'KecDetails',
'from' => 'src_kecamatan',
'foreignField' => 'id',
'localField' => 'idKecamatan'
]
],
[
'$lookup' => [
'as' => 'KotDetails',
'from' => 'src_kota_kabupaten',
'foreignField' => 'code',
'localField' => 'idKota'
]
],
[
'$lookup' => [
'as' => 'ProvDetails',
'from' => 'src_provinsi',
'foreignField' => 'idProv',
'localField' => 'idProvinsi'
]
],
['$skip' => ($page - 1) * $perPage],
['$limit' => $perPage],
]);
});
$dapil_kotkab = new \Illuminate\Pagination\LengthAwarePaginator($collection, $total, $perPage, $page, [
'path' => \Illuminate\Pagination\Paginator::resolveCurrentPath(),
]);
return view('dapil_kotakab.dapil_kotkabresult',compact('dapil_kotkab','word'))->with('i',(request()->input('page',1)-1)*20);
我的结果
<td>{{$dapil_kotakab->ProvDetails[0]->province}}</td>
<td>{{$dapil_kotakab->KotDetails[0]->regency}}</td>
<td>{{$dapil_kotakab->KecDetails[0]->name}}</td>
我已经尝试了好几次,但是我总是出错。
在这方面的任何建议将不胜感激。