【问题标题】:laravel load function with DB::table带有 DB::table 的 laravel 加载函数
【发布时间】:2018-02-16 02:13:40
【问题描述】:

我如何使用 Laravel load 函数和 DB::table 如下

DB::table('table_name)->where('field', 'value')->load('relation_1')->get();

或此声明的替代方式

【问题讨论】:

  • 请查看帮助中心并了解如何在 stackoverflow 上提问:stackoverflow.com/help/how-to-ask
  • DB 查询构建器不处理关系。这些是使用Eloquent 模型完成的。

标签: php laravel laravel-eloquent


【解决方案1】:

你可以直接写喜欢

DB::table('users')->get();

DB::table('users')
    ->select(DB::raw('count(*) as user_count, status'))
    ->where('status', '<>', 1)
    ->groupBy('status')
    ->get();

【讨论】:

    【解决方案2】:
    Post::all()->where('field_name', 'value')->load('relation_1','relation_2');
    

    我无法对 DB::table 使用加载函数 我创建了一个名为 Post 的模型,并使用了 where 函数并加载

    【讨论】:

      猜你喜欢
      • 2016-12-31
      • 2015-04-13
      • 1970-01-01
      • 2019-03-22
      • 2015-02-23
      • 1970-01-01
      • 2016-11-26
      • 2018-05-03
      • 2018-12-11
      相关资源
      最近更新 更多