Skip to content

Commit

Permalink
Update database seeder depending on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesPong committed Mar 12, 2018
1 parent 5888003 commit fbc1b50
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 59 deletions.
6 changes: 0 additions & 6 deletions database/seeds/CategoriesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ class CategoriesTableSeeder extends Seeder
*/
public function run()
{
factory(\App\Models\Category::class)->create([
'name' => 'uncategorized',
'description' => 'Default category',
'slug' => 'uncategorized'
]);

factory(\App\Models\Category::class, 15)->create();
}
}
20 changes: 12 additions & 8 deletions database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->call(PermissionsTableSeeder::class);
$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
$this->call(CategoriesTableSeeder::class);
$this->call(TagsTableSeeder::class);
$this->call(PostsTableSeeder::class);
$this->call(PagesTableSeeder::class);
$this->call(SettingsTableSeeder::class);
$this->call(InitializationSeeder::class);

if (app()->environment('local')) {
$this->call(PermissionsTableSeeder::class);
$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
$this->call(CategoriesTableSeeder::class);
$this->call(TagsTableSeeder::class);
$this->call(PostsTableSeeder::class);
$this->call(PagesTableSeeder::class);
$this->call(SettingsTableSeeder::class);
}
}
}
76 changes: 76 additions & 0 deletions database/seeds/InitializationSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

use Illuminate\Database\Seeder;

class InitializationSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(\App\Models\User::class)->create([
'name' => 'Miles Peng',
'email' => '[email protected]',
'password' => bcrypt('indigo')
]);

factory(\App\Models\Category::class)->create([
'name' => 'Uncategorized',
'description' => 'Default category',
'slug' => 'uncategorized'
]);

factory(\App\Models\Page::class)->create([
'title' => 'About',
'slug' => 'about',
'description' => null,
'user_id' => \App\Models\User::first()->id,
'content_id' => factory(\App\Models\Content::class)->create([
'body' => "## This is the about page."
])->id,
'view_count' => 0,
'is_draft' => false,
'deleted_at' => null
]);

factory(\App\Models\Page::class)->create([
'title' => 'Links',
'slug' => 'links',
'description' => null,
'user_id' => \App\Models\User::first()->id,
'content_id' => factory(\App\Models\Content::class)->create([
'body' => "## This is the links page."
])->id,
'view_count' => 0,
'is_draft' => false,
'deleted_at' => null
]);

factory(\App\Models\Setting::class)->create([
'key' => 'title',
'value' => "Miles' Blog",
'tag' => 'website'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'keywords',
'value' => 'miles,milespong,laravel,blog',
'tag' => 'seo'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'description',
'value' => 'A blog built with laravel by Miles',
'tag' => 'seo'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'heading',
'value' => 'Just Keep Learning',
'tag' => 'website'
]);
}
}
14 changes: 0 additions & 14 deletions database/seeds/PagesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ class PagesTableSeeder extends Seeder
*/
public function run()
{
factory(\App\Models\Page::class)->create([
'title' => 'About',
'slug' => 'about',
'is_draft' => false,
'deleted_at' => null
]);

factory(\App\Models\Page::class)->create([
'title' => 'Links',
'slug' => 'links',
'is_draft' => false,
'deleted_at' => null
]);

factory(\App\Models\Page::class, 5)->create();
}
}
3 changes: 2 additions & 1 deletion database/seeds/PostsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class PostsTableSeeder extends Seeder
*/
public function run()
{
// $tagCount = \App\Models\Tag::count();

factory(\App\Models\Post::class, 30)->create()->each(function (\App\Models\Post $post) {
$tagCount = \App\Models\Tag::count();
$post->tags()->sync(\App\Models\Tag::inRandomOrder()->take(mt_rand(1, 4))->get());
// $post->tags()->attach(App\Models\Tag::all()->random(rand(1, App\Models\Tag::count())));
});
Expand Down
24 changes: 0 additions & 24 deletions database/seeds/SettingsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,6 @@ class SettingsTableSeeder extends Seeder
*/
public function run()
{
factory(\App\Models\Setting::class)->create([
'key' => 'title',
'value' => "Miles' Blog",
'tag' => 'website'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'keywords',
'value' => 'miles,milespong,laravel,blog',
'tag' => 'seo'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'description',
'value' => 'A blog built with laravel by Miles',
'tag' => 'seo'
]);

factory(\App\Models\Setting::class)->create([
'key' => 'heading',
'value' => 'Just Keep Learning',
'tag' => 'website'
]);

factory(\App\Models\Setting::class, 5)->create();
}
}
6 changes: 0 additions & 6 deletions database/seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ class UsersTableSeeder extends Seeder
*/
public function run()
{
factory(\App\Models\User::class)->create([
'name' => 'Miles Peng',
'email' => '[email protected]',
'password' => bcrypt('123123')
]);

factory(\App\Models\User::class, 10)->create()->each(function ($user) {
$user->roles()->sync(\App\Models\Role::all()->random(rand(1, \App\Models\Role::count())));
});
Expand Down

0 comments on commit fbc1b50

Please sign in to comment.