yes you can do it
But its Not Recommended
Step 1:
Run the Command php artisan make:migration create_bulk_table
Now open your migration folder inside the database/migrations
you will find the new migration time_stamp_create_bulk_table.php
open it You will find the Contents like this
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBulkTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bulk', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('bulk');
}
}
How To Do it
There are two methods in this
one is for creating the table
that is up METHOD
and
another one is for dropping the table
that is down METHOD
For Example if You want to migrate
posts
table ,tasks
table ,products
table
In Single Migration
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBulkTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('posts'))
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('post_name');
$table->text('post_desc');
$table->timestamps();
});
}
if (!Schema::hasTable('tasks'))
{
Schema::create('tasks', function (Blueprint $table) {
$table->increments('id');
$table->string('task_name');
$table->enum('task_status', ['Open', 'Closed','Inactive']);
$table->text('task_desc');
$table->timestamps();
});
}
if (!Schema::hasTable('products'))
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('product_name');
$table->text('product_desc');
$table->string('product_price');
$table->timestamps();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
Schema::dropIfExists('tasks');
Schema::dropIfExists('products');
}
}
BE CAREFUL WHILE REFERING THE FORIEGN KEY OF PARENT TABLE WHICK NEEDS TO BE CREATED BEFORE THE REFERAL
For Example You have column user_id
in post table Which you are refering like
$table->foreign('user_id')->references('id')->on('users');
users
table needs to be migrated before the posts
table
Hope it is clear
Kindly Comment below if you find any bugs