In the current web applications, storing structured data in JSON (JavaScript Object Notation) format has become more common. You may be storing user preferences, various app settings, API responses, or product attributes, etc. JSON provides a flexible solution for storing structured data that is also lightweight. Laravel is a powerful and impactful PHP framework that also makes it easy to manage JSON data.

In this blog, we will learn how to store JSON-formatted data into a database using Laravel.
Prerequirement:
- Composer (latest Version)
- Laravel version 12
Steps to Store JSON Format Data in Database for Laravel:
Step 1: Create a New Laravel Project
composer create-project laravel/laravel json-demo-project
cd json-demo-project
Step 2: Create a student migration
Here, we need to create a database migration for the “students” table with “name” and “details” (JSON Column) columns, and we will also create a model for the students table.
php artisan make:migration create_students_table
Edit the created migration file as below,
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->string("name");
$table->json("details")->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('students');
}
};
Step 3: Create Model
php artisan make:model Student
App/Models/Student.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
use HasFactory;
protected $fillable = [
'name', 'details'
];
protected $casts = [
'details' => 'json'
];
}
Step 4: Create Students
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StudentController;
Route::get('students/create', [StudentController::class, 'create']);
app/Http/Controllers/StudentController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Student;
class StudentController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function create()
{
$input = [
'name' => 'Jay',
'details' => [
'age' => '21',
'city' => 'surat'
]
];
return Student::create($input);
}
}
Step 5: Get the students data
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StudentController;
routes/web.php
Route::get('students/search', [StudentController::class, 'search']);
in app/Http/Controllers/StudentController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Student;
class StudentController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function search()
{
$students = Student::whereJsonContains('details->city', 'surat')->get();
return $students;
}
}
Output:
{
"name": "jay",
"details": {
"age": "21",
"city": "surat"
},
"updated_at": "2025-08-12T13:12:44.000000Z",
"created_at": "2025-08-12T13:12:44.000000Z",
"id": 1
}
Conclusion:
Storing JSON format data in a database with Laravel is simple yet powerful. If your application needs dynamic attributes or complex metadata, JSON storage in Laravel is a go-to solution!

Happy Coding!
FAQ
- What is Laravel?
Laravel is a web application framework with an elegant and expressive syntax that provides a foundation and starting point for creating web applications in PHP.
- Why Choose Laravel?
Laravel has a robust set of features, including an expressive database abstraction layer (Eloquent), a powerful templating engine (Blade), built-in authentication and authorization, an expressive routing system, queues, scheduled tasks, and a command line tool (Artisan CLI). One of the biggest focuses of Laravel is the developer experience, and it has tons of powerful tools to help with that experience.