Laravel whereJsonContains Query Example

Hello devs

In this tutorial i will discouss about laravel wherejsoncontains method. You will know wherejsoncontains laravel example from this example tutorial. Sometimes you know that we need to use json columns or json array. So that time we need to set a condition for that json array or json field.

In this laravel query where json contains example i will show you how we can write a query using laravel wherejsoncontains. Let's see the example query.

$users = DB::table('users')
                ->whereJsonContains('category_id', $request->id)


Where category_id is a json field. Keep in mind that it is not supported on SQLite.

MySQL and PostgreSQL support whereJsonContains with multiple values in Laravel:

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


Read also : Avoid Pivot Table and Use Json Column in Laravel


Hope this Laravel wherejsoncontains query tutorial will help you.


Facebook Github
A web enthusiastic, self-motivated Full-Stack Web Developer from Dhaka, Bangladesh with experience in developing applications using Laravel Vue and React Js Application.