【问题标题】:Laravel - Query a model when calling allLaravel - 调用全部时查询模型
【发布时间】:2018-04-30 17:50:26
【问题描述】:

是否可以在 laravel 中使用

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

但是得到所有匹配查询的例子

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

【问题讨论】:

    标签: laravel eloquent query-builder


    【解决方案1】:

    使用get()

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

    【讨论】:

      【解决方案2】:

      你可以使用 filter() 函数

      $flights = App\Flight::all(); $flights = $flights->filter(function($flight) 使用 ($flightCaptainId) { 返回 $flight->pilotID == $flightCaptainId; });

      【讨论】:

        猜你喜欢
        • 2018-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多