【问题标题】:Laravel Query Builder - Complex select column errorLaravel 查询生成器 - 复杂的选择列错误
【发布时间】:2015-12-24 12:26:08
【问题描述】:

我有两张这样的桌子-

小组成员

用户

我有一个像这样的 Laravel 5.1 查询构建器-

    $baseQuery = DB::table('panelists')
        ->join('users', 'panelists.user_id', '=', 'users.id')
        ->select(
            'users.id',
            'users.name',
            'users.email',
            'IF(enabled=1,"English Book","Other Language")   AS status'
        )
        ->where('panelists.customer_id', '=', $user_ID);

但它给了我错误

          'IF(enabled=1,"English Book","Other Language")   AS status'

有人可以帮忙吗?

【问题讨论】:

  • 发布确切的错误信息
  • 尝试 DB::raw 进行原始查询。

标签: php mysql laravel laravel-5 query-builder


【解决方案1】:

试试这个:您可以使用DB::Raw 进行原始查询。

$baseQuery = DB::table('panelists')
    ->join('users', 'panelists.user_id', '=', 'users.id')
    ->select(
        'users.id',
        'users.name',
        'users.email',
         DB::raw('IF(enabled=1,"English Book","Other Language")AS status')
    )
    ->where('panelists.customer_id', '=', $user_ID);

【讨论】:

    猜你喜欢
    • 2015-12-21
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    相关资源
    最近更新 更多