How to Add Mediumblob Data Type using Laravel Migration?
Hi Dev,
Now, let's see an example of laravel migration mediumblob data type. We will use laravel mediumblob migration. This article goes in detailed on laravel migration mediumblob. step by step explain how to add mediumblob in laravel migration. So, let us see in detail an example.
Laravel migration provides only blob data type. IF you want to add Mediumblob column then you need to core sql query to add it using migration. I will create simple files table with mediumblob data type. so, let's see the simple example code:
Example:
Here, we will create files table with add Mediumblob 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 MEDIUMBLOB");
}
/**
* 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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Migration Remove Auto Increment Example
- How to Drop Primary Key in Laravel Migration?
- How to Add Primary Key in Laravel Migration?
- How to Drop Index in Laravel Migration?
- How to Drop Unique Constraint in Laravel Migration?
- Laravel Migration Unique Multiple Columns Example
- How to Add Unique Constraint in Laravel Migration?
- How to Add Boolean Column in Laravel Migration?
- How to Change Column Position in Laravel Migration?
- How to Add Foreign Key in Laravel Migration?
- How to Change Table Name using Laravel Migration?
- How to Remove Column from Table in Laravel Migration?