ItSolutionStuff.com

How to Add Blob Data Type using Laravel Migration?

By Hardik Savani • November 5, 2023
Laravel

Hello Dev,

In this post, we will learn laravel migration blob. you will learn how to add blob data type in laravel migration. This example will help you laravel migration binary type. In this article, we will implement a laravel migration blog image store. So, let's follow a few steps to create an example of Laravel migration blob column.

Laravel migration provides binary() method to add mysql blob data type in laravel project. I will create simple products table with blob data type. so, let's see the simple example code:

Example:

Here, we will create products table with add Blob to data type.

Create new migration using following command:

php artisan make:migration create_products_table

Now, You can update it as like the bellow:

database/migrations/migration_name.php

<?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('products', function (Blueprint $table) {

$table->id();

$table->string('name');

$table->text('description');

$table->binary('image')->nullable();

$table->timestamps();

});

}

/**

* Reverse the migrations.

*/

public function down(): void

{

Schema::dropIfExists('products');

}

};

Now, you are ready to run migration command:

php artisan migrate

You will see the layout as like the below:

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Drop Primary Key in Laravel Migration?

Read Now →

How to Add Primary Key in Laravel Migration?

Read Now →

How to Drop Index in Laravel Migration?

Read Now →

How to Drop Unique Constraint in Laravel Migration?

Read Now →

Laravel Migration Unique Multiple Columns Example

Read Now →

How to Add Boolean Column in Laravel Migration?

Read Now →

Laravel Migration Change Datatype String to Integer Example

Read Now →

Laravel Migration Add Column After Column Example

Read Now →

How to Change Column Length using Laravel Migration?

Read Now →

Laravel Migration Enum Default Value Example

Read Now →

Laravel Migration Custom Index Name Example

Read Now →

How to Change Table Name using Laravel Migration?

Read Now →

How to Change Column Name and Data Type in Laravel Migration?

Read Now →