1

I have 2 table like this-

panelists

enter image description here

users

enter image description here

I have a Laravel 5.1 query builder like this-

    $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);

But it is giving me error for

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

Can anyone help please?

2
  • 1
    Post exact error message Commented Sep 26, 2015 at 23:59
  • 1
    Try DB::raw for raw queries. Commented Sep 27, 2015 at 0:45

1 Answer 1

1

Try this: You may use DB::Raw for raw queries.

$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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.