Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gerrymcdonnell/9df953be909cde3d073b04efd5bfe1c0 to your computer and use it in GitHub Desktop.
Save gerrymcdonnell/9df953be909cde3d073b04efd5bfe1c0 to your computer and use it in GitHub Desktop.
Laravel-migration with multiple record insertion
<?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