0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Laravel】ORMを用いた、JSON型のカラムに対しての検索条件記述方法

0
Posted at

メモとして残します。

細かい機能レベル権限をJSON型カラムを用意してjson形式でDB管理。
whereで検索しようとしたときに、「どうやって検索するんだ?」となったため、メモ。

■前提

EroquentモデルでテーブルにJSON型のカラムをメンバ変数$castsにjson型で扱うように定義。

class User extends Model
{
    protected $casts = [
        'JSON型のカラム名' => 'json', //jsonでなく、確かarrayでも可
    ];
}

■やり方

$user = User::where('JSON型のカラム名->hogehoge', "条件")
            ->get();

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?