Skip to content

Instantly share code, notes, and snippets.

@patrickmaciel
Last active August 29, 2015 14:17
Show Gist options
  • Save patrickmaciel/1d3a8007897907d8ee48 to your computer and use it in GitHub Desktop.
Save patrickmaciel/1d3a8007897907d8ee48 to your computer and use it in GitHub Desktop.
SQL Server DatabaseSeeder and Seeders in Laravel 4.2
<?php
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
// DB::unprepared ('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"');
DB::table('contato_importacoes')->delete();
$this->call('EscolaridadesTableSeeder');
// DB::unprepared ('EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"');
}
}
<?php
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class SalasTableSeeder extends Seeder {
public function run()
{
// DB::unprepared ('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"');
DB::unprepared ('SET IDENTITY_INSERT tb_salas ON');
DB::table('salas')->delete();
$salas = array(
array(
'id' => 1,
'nome' => 'Sala 1',
'descricao' => 'Sala 1',
'lotacao' => 30,
'ativo' => 1,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
'deleted_at' => NULL
),
array(
'id' => 2,
'nome' => 'Sala 2',
'descricao' => 'Sala 2',
'lotacao' => 30,
'ativo' => 1,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
'deleted_at' => NULL
),
array(
'id' => 3,
'nome' => 'Sala 3',
'descricao' => 'Sala 3',
'lotacao' => 30,
'ativo' => 1,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
'deleted_at' => NULL
)
);
// Uncomment the below to run the seeder
DB::table('salas')->insert($salas);
// DB::unprepared ('EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"');
DB::unprepared ('SET IDENTITY_INSERT tb_salas OFF');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment