Laravel JSON data search from the database; laravel JSON data filter using where clauses. In this post, I will teach you how to find or filter data that you store in the database in JSON format in the table column. Laravel provides a method to easy way to find or search data from the database column.
The whereJsonContains() method will help us to filter and find JSON data from the database table column. At the end of this post, you will say to filter and apply where caused in the laravel query to find JSON content.
To filter data based on JSON content and searchable based on it. i have add a post column inside the users table.
Now I want to find user who has red color, So using laravel JSON where method i will find inside the post->color column object. follow the below given example.
JSON DATA EXAMPLE :
{ "color":"red", "value":"#f00" }, { "color":"green", "value":"#0f0" }, { "color":"blue", "value":"#00f" }
Attributes Set In Laravel Model
JSON Data Database Preview :

You can see I have stored JSON objects inside the post column in the database.
Example OF Filter :
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; class HomeController extends Controller { public function index(Request $request) { $user = User::query(); if($request->has('color')) { $user = $user->whereJsonContains('post->color', $request->color); } $user = $user->get(); dd($user); } }
whereJsonContains method provides easy why find or filter JSON store data in the database.
We always thanks to you for reading our blogs.

Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Route Resource Controller Laravel
- Laravel Adding Social Media Share buttons Advanced Tutorial Example
- Laravel One to Many Eloquent Relationship Tutorial With Example
- Upayments Gateway Integration PHP - Laravel
- How to Integrate Razorpay Payment Gateway in Laravel 9 Example
- Error : Trying To Get Property Of ID Non-Object All Possible Solution Guideline In Laravel - PHP
- How To Insert Current Datetime In Database Laravel
- UPI Payment Gateway Integration in PHP/Laravel
- could not find driver (SQL: select count(*) as aggregate from "users" where "email" = admin@gmail.com)
- db raw multiple when case sum laravel