LoginSignup
0
0

More than 1 year has passed since last update.

laravel クエリビルダ where句にて「〇〇以外」で絞り込む方法

Last updated at Posted at 2021-11-25

目的

  • クエリビルダのwhere句にて〇〇以外で絞り込む方法をまとめる

概要

  • usersテーブルにflagカラムがあったとする。
  • flagカラムにはintの0、intの1、intの2いずれか格納されている。
  • flagカラムが1以外のレコードを取得したい場合のwhere句の書き方をまとめる

ご注意

  • 「 〇〇以外」にNULLを含みたい場合は本方法では無理である。
  • where句ではnullを判定することができない。
  • orWhereNull句やグループ化などを用いて記載する必要がある。

方法

  • 下記の様にwhere句を記載することでflagカラムが1以外のレコードを取得することができる。

    $users = DB::table('users')
        ->where('flag', '!=', 1)
        ->get();
    

関連記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0