Can we use join or aggregrate in laravel with model? #2509
-
|
Can we use join or aggregrate in laravel with model? i have try to do it but I am getting error: My model: `<?php namespace Modules\Report\Entities; use Jenssegers\Mongodb\Eloquent\Model; class ReportOutput extends Model } my controller function : |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You’re getting the error because the method name is misspelled. It should be Here is the corrected controller code: return ReportOutput::raw(function ($collection) use ($siteId) {
return $collection->aggregate([
[
'$match' => [
'site_id' => $siteId
]
],
[
'$lookup' => [
'from' => 'websites',
'localField' => 'site_id',
'foreignField' => '_id',
'as' => 'info'
]
]
])->toArray();
}); |
Beta Was this translation helpful? Give feedback.
You’re getting the error because the method name is misspelled. It should be
aggregate(), notaggregrate(). Also,aggregate()accepts a single pipeline array.Here is the corrected controller code: