ItSolutionStuff.com

How to Add Longblob Data Type using Laravel Migration?

By Hardik Savani • November 5, 2023
Laravel

Hey Guys,

This article will provide some of the most important example laravel migration longblob data type. I’m going to show you about laravel longblob migration. I would like to share with you laravel migration longblob. I would like to show you how to add longblob in laravel migration. So, let us see in detail an example.

Laravel migration provides only blob data type. IF you want to add longblob column then you need to core sql query to add it using migration. I will create simple files table with longblob data type. so, let's see the simple example code:

Example:

Here, we will create files table with add longblob to data type.

Create new migration using following command:

php artisan make:migration create_files_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;

use Illuminate\Support\Facades\DB;

return new class extends Migration

{

/**

* Run the migrations.

*/

public function up(): void

{

Schema::create('files', function (Blueprint $table) {

$table->id();

$table->string('name');

$table->string('mime');

$table->timestamps();

});

DB::statement("ALTER TABLE files ADD file LONGBLOB");

}

/**

* Reverse the migrations.

*/

public function down(): void

{

Schema::dropIfExists('files');

}

};

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 Migrate SQL File in Laravel Migration?

Read Now →
ā˜…

Laravel Migration Remove Default Value Example

Read Now →
ā˜…

Laravel Migration Change Default Value Example

Read Now →
ā˜…

Laravel Migration Change Datatype Integer to Decimal Example

Read Now →
ā˜…

Laravel Migration Change Datatype Int to Bigint Example

Read Now →
ā˜…

Laravel Migration Change Datatype String to Integer Example

Read Now →
ā˜…

How to Add Index in Laravel Migration?

Read Now →
ā˜…

Laravel Migration - How to Add New Column in Existing Table ?

Read Now →
ā˜…

How to Change Table Name using Laravel Migration?

Read Now →
ā˜…

How to Remove Column from Table in Laravel Migration?

Read Now →
ā˜…

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

Read Now →