2017-08-24 5 views
0

Laravelで偽の列名を使用する必要があるクエリがあります。コードは問題ありませんでしたが、問題は'"0" as lang_id','"0" as qst_story',でした。laravel 5.4で偽の列名を作成するには?

私はこれを行う必要がある理由、私の前のテーブルは、古い列名を使用します。だから私は私の前のコードと一致するために偽の列名を提供する必要があります。

誰でも手伝ってもらえますか?ありがとう。

現在のコード:

$question_content = DB::connection('mysql_pencil_content') 
       ->table('cms_qst_master_content as qmc') 
//    ->with(['ImageContentGallery']) 
       ->leftJoin('cms_qst_explaination as exp','exp.explaination_id','=','qmc.content_explaination_id') 
       ->where('qmc.question_id',$main['question_id']) 
//    ->groupBy('lang_id') 
       ->get(['qmc.*', 
        'qmc.content_id as qst_cnt_id', 
        'qmc.question_id', 
        'qmc.content_text as qst_cnt_text', 
        'qmc.content_option as qst_cnt_options', 
        '"0" as qst_story', 
        'exp.explaination_text as explanation', 
        '"0" as lang_id', 
        'qmc.content_image_id as image_id', 
        'qmc.dt_update'])->toSql(); 
     pre($question_content); 

問題:

QueryException in Connection.php line 729: 
SQLSTATE[42S22]: Column not found: 1054 Unknown column '"0"' in 'field list' (SQL: select `qmc`.*, `qmc`.`content_id` as `qst_cnt_id`, `qmc`.`question_id`, `qmc`.`content_text` as `qst_cnt_text`, `qmc`.`content_option` as `qst_cnt_options`, `"0"` as `qst_story`, `exp`.`explaination_text` as `explanation`, `"0"` as `lang_id`, `qmc`.`content_image_id` as `image_id`, `qmc`.`dt_update` from `cms_qst_master_content` as `qmc` left join `cms_qst_explaination` as `exp` on `exp`.`explaination_id` = `qmc`.`content_explaination_id` where `qmc`.`question_id` = 200001) 

答えて

1

を使用できDB::raw

DB::connection('mysql_pencil_content') 
       ->table('cms_qst_master_content as qmc') 
//    ->with(['ImageContentGallery']) 
       ->leftJoin('cms_qst_explaination as exp','exp.explaination_id','=','qmc.content_explaination_id') 
       ->where('qmc.question_id',$main['question_id']) 
->select('qmc.*', 
     'qmc.content_id as qst_cnt_id', 
     'qmc.question_id', 
     'qmc.content_text as qst_cnt_text', 
     'qmc.content_option as qst_cnt_options', 
     DB::raw('0 as qst_story'), 
     'exp.explaination_text as explanation', 
      DB::raw('0 as lang_id'), 
     'qmc.content_image_id as image_id', 
     'qmc.dt_update' 
) 
->get(

関連する問題