Created
February 11, 2018 15:21
-
-
Save gerrymcdonnell/9df953be909cde3d073b04efd5bfe1c0 to your computer and use it in GitHub Desktop.
Laravel-migration with multiple record insertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateRolesTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('roles', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('name'); | |
$table->timestamps(); | |
}); | |
//create 3 roles records | |
$rows = [ | |
[ | |
'id'=>1, | |
'name' => 'administrator' | |
], | |
[ | |
'id'=>2, | |
'name' => 'author' | |
], | |
[ | |
'id'=>3, | |
'name' => 'subscriber' | |
] | |
]; | |
// insert records | |
DB::table('roles')->insert($rows); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('roles'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment