laravel whereJsonContains code example

Example 1: limit laravel

$posts = Post::all()->limit(10)->get();

Example 2: laravel not in query

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();

Example 3: laravel query json

$users = DB::table('users')
                ->whereJsonContains('options->languages', ['en', 'de'])
                ->get();

Example 4: whereJsonContains laravel

The data types have to match:

// [1, 2]
->whereJsonContains('players', 1)   // Works.
->whereJsonContains('players', '1') // Doesn't work.

// ["1", "2"]
->whereJsonContains('players', '1') // Works.
->whereJsonContains('players', 1)   // Doesn't work.