That should be no problem, but it's good practice to have one migration for each table.
However, you just have to run two Schema::create instead of one.
What have you tried so far?
I am using a single class and single file for multiple schema.. but when I gives the command php artisan migrate in the cli it creates only first table why this I don't know,I need these all tables to be created in the database in the single time.. like this is the full code below,
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePortfolioTables extends Migration { /** * Run the migrations. * * @return void */ public function up() { # Type of Portfolio, i.e. Hotel/Zip/City/Metro/County/Franchise Schema::create('portfolio_type', function($table) { $table->increments('id'); $table->string('name',20)->unique(); }); # Instances of users' Portfolios, which (for now) contain hotels added by the user Schema::create('portfolio_user', function($table) { $table->increments('id'); $table->string('name',100); # Portfolio is of a certain type. As of v1 default to type "Hotel" $table->integer('type')->unsigned(); $table->foreign('type')->references('id')->on('portfolio_type'); # Portfolio is "owned" by the user that created it $table->integer('owner')->unsigned()->index(); # Drop the portfolio if the user is deleted for some reason $table->foreign('owner')->references('id')->on('auth_user')->onDelete('cascade'); # Maintain created/updated information $table->timestamps(); # Combination of portfolio name + owner/user ID should be unique # That is, no single user should be allowed to have 2 portfolios with identical names $table->unique(array('name', 'user')); }); # Contents of (i.e. list of hotels in) a single user portfolio Schema::create('portfolio_user_hotel', function($table) { $table->increments('id'); # FK to the PK of the portfolio this meta-record belongs in $table->integer('portfolio')->unsigned()->index(); $table->foreign('portfolio')->references('id')->on('portfolio_user')->onDelete('cascade'); # FK to the PK of the hotel that's in this portfolio $table->integer('place')->unsigned(); $table->foreign('place')->references('id')->on('place_hotel')->onDelete('cascade'); # Not used for v1, but will be for v1.1+ $table->decimal('noirate', 5, 2); $table->decimal('caprate', 5, 2); # Maintain created/updated information $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('portfolio_type'); Schema::drop('portfolio_user'); Schema::drop('portfolio_user_hotel'); } }Uh...I would think it is because Schema:: runs your create closure and returns. It would never get to your next Schema call. You gotta jam all of that into one Schema call, or better, create one migration file per table.
Is there a reason they can't go in different migration files? If you pull in way/generators it isn't tough... just a copy and paste. You wouldn't have to call every migration separately, once they are created, they can all get executed at once...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community