ユーザ用ツール

サイト用ツール


プログラム言語:php:laravel:クエリビルダ:join

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
プログラム言語:php:laravel:クエリビルダ:join [2020/01/10 11:49]
humolife 作成
プログラム言語:php:laravel:クエリビルダ:join [2021/10/15 16:18] (現在)
humolife [LEFT JOIN]
行 1: 行 1:
 ====== Laravelのクエリビルダ:JOIN ====== ====== Laravelのクエリビルダ:JOIN ======
-===== LEFT JOIN =====+===== INNER JOIN =====
 <code> <code>
 $users = DB::table('users') $users = DB::table('users')
-    ->leftJoin('posts', 'users.id', '=', 'posts.user_id')+    ->join('posts', 'users.id', '=', 'posts.user_id')
     ->get();     ->get();
 </code> </code>
  
-LEFT JOIN の中で、さらに AND など複数の条件で絞り込みたい場合は、use で変数を渡せます。+JOIN の中で、さらに AND など複数の条件で絞り込みたい場合は、use で変数を渡せます。
 <code> <code>
 $users = DB::table('users') $users = DB::table('users')
-    ->leftJoin('posts', function ($join) use ($pref) {+    ->join('posts', function ($join) use ($pref) {
         $join->on('users.id', 'posts.user_id')         $join->on('users.id', 'posts.user_id')
             ->where('posts.pref', $pref);             ->where('posts.pref', $pref);
     })     })
-    ->where('posts.pref', $pref) 
     ->get();     ->get();
 </code> </code>
  
プログラム言語/php/laravel/クエリビルダ/join.txt · 最終更新: 2021/10/15 16:18 by humolife