/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('phones'); $authors = \App\Author::all(); foreach ($authors as $author) { \App\Phone::create(['author_id' => $author->id, 'phone_number' => '0' . (string) (9099990000 + $author->id)]); } }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('dvds'); factory(\App\Dvd::class, 200)->create()->each(function (\App\Dvd $dvd, $i) { // 書籍名に連番を付与 $dvd->update(['title' => $dvd->title . ($i + 1)]); }); }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('prefectures'); $prefectures = [1 => '北海道', 2 => '青森県', 3 => '岩手県', 4 => '宮城県', 5 => '秋田県', 6 => '山形県', 7 => '福島県', 8 => '茨城県', 9 => '栃木県', 10 => '群馬県', 11 => '埼玉県', 12 => '千葉県', 13 => '東京都', 14 => '神奈川県', 15 => '新潟県', 16 => '富山県', 17 => '石川県', 18 => '福井県', 19 => '山梨県', 20 => '長野県', 21 => '岐阜県', 22 => '静岡県', 23 => '愛知県', 24 => '三重県', 25 => '滋賀県', 26 => '京都府', 27 => '大阪府', 28 => '兵庫県', 29 => '奈良県', 30 => '和歌山県', 31 => '鳥取県', 32 => '島根県', 33 => '岡山県', 34 => '広島県', 35 => '山口県', 36 => '徳島県', 37 => '香川県', 38 => '愛媛県', 39 => '高知県', 40 => '福岡県', 41 => '佐賀県', 42 => '長崎県', 43 => '熊本県', 44 => '大分県', 45 => '宮崎県', 46 => '鹿児島県', 47 => '沖縄県']; foreach ($prefectures as $id => $name) { DB::table('prefectures')->insert(['id' => $id, 'name' => $name]); } }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('publishers'); factory(\App\Publisher::class, 50)->create(); factory(\App\Publisher::class, 200)->create()->each(function (\App\Publisher $publisher, $key) { // ローマ字に連番を付与 $publisher->update(['romaji' => $publisher->romaji . ' ' . ($key + 1)]); }); }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::$massSeed = true; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS = 0'); $this->call(UlibierSeeder::class); $this->call(ArticleSeeder::class); $this->call(Destinations::class); $this->call(PhotoSeeder::class); $this->call(ArticleDestinationMappingSeeder::class); $this->call(TagSeeder::class); Model::reguard(); DB::statement('SET FOREIGN_KEY_CHECKS = 1'); DatabaseSeeder::$massSeed = false; }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('author_author_type'); DatabaseSeeder::truncateTable('author_types'); try { factory(\App\AuthorType::class, 10)->create(); } catch (\Illuminate\Database\QueryException $e) { // name カラムの unique index の無視 } $authors = \App\Author::all(); /** @var \App\Author $author */ foreach ($authors as $author) { $author_types = \App\AuthorType::all()->random(rand(2, 5)); $author->types()->sync($author_types); } }
/** * Run the database seeds. * * @return void */ public function run() { // (1) データを一旦削除する DatabaseSeeder::truncateTable('authors'); // (2) DBファサードを利用したデータの挿入 $authors = []; $now = \Carbon\Carbon::now(); for ($i = 1; $i <= 10; $i++) { $authors[] = ['name' => '著者名' . $i, 'furigana' => 'フリガナ' . $i, 'romaji' => 'Romaji' . $i]; } foreach ($authors as $author) { $author['created_at'] = $now; $author['updated_at'] = $now; DB::table('authors')->insert($author); } // (3) Eloquentを利用したデータの挿入 for ($i = 11; $i <= 20; $i++) { \App\Author::create(['name' => '著者名' . $i, 'furigana' => 'フリガナ' . $i, 'romaji' => 'Romaji' . $i]); } }
private function seedQuizmaster() { $addresses = ['Home', 'Work', 'Church', 'Vacation Home']; $savedAddresses = []; foreach ($addresses as $key => $name) { $savedAddresses[] = factory(Address::class)->create(['name' => $name]); } self::$guardian = User::create(['status' => User::STATUS_CONFIRMED, 'first_name' => 'Ben', 'last_name' => 'Quizmaster', 'email' => self::QUIZMASTER_EMAIL, 'phone' => '5553546789', 'password' => bcrypt('changeme'), 'primary_address_id' => $savedAddresses[0]->id]); self::$guardian->addresses()->saveMany($savedAddresses); }
public function destroy(\DatabaseSeeder $seeder) { $seeder->run(); flash()->success('Data has been deleted'); return redirect()->back(); }
private function seedDatabase() { $directory = $this->config['info']['alias']; $seed_dir = app_path('Modules/' . $directory . '/Database/Seeds'); foreach (File::files($seed_dir) as $file) { require_once $file; } $seeder = new \DatabaseSeeder(); $seeder->run(); }
private function seedDatabase() { $directory = $this->config['info']['alias']; if (isset($this->config['info']['vendor'])) { $vendor = $this->config['info']['vendor'] . '/'; } else { $vendor = ''; } $seed_dir = app_path('Modules/' . $vendor . $directory . '/Database/Seeds'); if (File::files($seed_dir)) { foreach (File::files($seed_dir) as $file) { require_once $file; } $seeder = new \DatabaseSeeder(); $seeder->run(); } }
Route::post('/{resource}', function ($resource) { return All::massUpdate($resource); }); Route::post('/suppliers/{resource}', function ($resource) { return All::massUpdateSupplier($resource); }); }); /* |-------------------------------------------------------------------------- | Seed and Empty tables like a Boss |-------------------------------------------------------------------------- | */ Route::get('{table}/seed', array('before' => 'admin', function ($table) { if (Sentry::getUser()->hasAccess('admin')) { DatabaseSeeder::seed($table); } // return var_dump(Sentry::getUser()->hasAccess('admin')); return Redirect::to($table); })); Route::get('{table}/empty', array('before' => 'admin', function ($table) { if (Sentry::getUser()->hasAccess('admin')) { // return DB::table($table)->get(); // foreach (DB::table($table)->get() as $record) { // $record->delete(); // } DB::table($table)->truncate(); // $model = All::getModel($table); // return $model::all(); // foreach ($model::all() as $record) { // $record->delete();
public function __construct() { parent::__construct(); $this->instructors = Instructor::all(); $this->section_types = SectionType::all(); $this->terms = ['W15', 'Sp15', 'Su15']; }
/** * @param \App\Repositories\TagRepository */ public function __construct(TagRepository $tagRepository) { parent::__construct(); $this->tagRepository = $tagRepository; }