Laravel - 在调用all时查询模型

时间:2018-04-30 17:50:27

标签: laravel eloquent query-builder

是否可以在laravel中使用

调用集合
$flights = App\Flight::all();

但获得所有匹配查询的例子

$flights = App\Flight::all()->where('pilotID', flightCaptainId);

2 个答案:

答案 0 :(得分:2)

使用UserLdap.aggregate([ { $lookup: { from: 'training_documents', // Search training documents collection... localField: 'trainings.document', // Search query is the object id of trainings array. foreignField: '_id', // key to compare against is _id of trainings[].document. as: 'trainings.document' // Return results in the trainings array on user. }, }, ]).exec((err, results) => { if (err) { console.log(err); } else { res.status(200).json(results); console.log(results); } })

get()

答案 1 :(得分:0)

您可以使用filter()函数


    $flights = App\Flight::all();
    $flights = $flights->filter(function($flight) use ($flightCaptainId)
                   {
                       return $flight->pilotID == $flightCaptainId;
                   });