2017-09-15 27 views
0

2つのDBを使用するための ".env"を設定した場合、以下のように使用するためのコードも作成しました。Laravel DB Faisade for join()を使用した結合クエリの場合

ただし、どこで()メソッドを使用するのが間違っていましたか。

where()メソッドを説明付きで使用するか、または学習するためのリンクを教えてください。

ありがとうございます。

$master = DB::connection('master_db')->table('customer_master') 
      ->where(['name', '=', 'string'], 
        ['tel', '=', 'integer'], 
        ['address','=', 'string']); 

$slave = DB::connection('slave_db')->table('customer_slave') 
      ->where(['histories', '=', 'string']) 
      ->union($master) 
      ->get(); 
+0

https://laravel.com/docs/5.5/queries#where-clauses – Devon

+0

あなたが以前に使用したwhere()の配列構文を見たことはありませんでしたが、何を求めているのかは分かりません。 SQLとバインディングを ' - > toSql()'と ' - > getBindings()'でダンプして、クエリ自体を調べることができます。 – Devon

答えて

0

は、このようなクエリを書く:

ここ
$master = DB::connection('master_db')->table('customer_master') 
    ->where([ 
     'name' => 'string', 
     'tel' => 'integer', 
     'address' => 'string' 
    ]); 

$slave = DB::connection('slave_db')->table('customer_slave') 
    ->where('histories', 'string') 
    ->union($master) 
    ->get(); 

配列構文は$master$slaveのために微調整where()のために微調整されています。 =の比較がデフォルトですので、ここで指定する必要はありません。

関連する問題