Skip to content

Commit

Permalink
Update WikisTableSeeder
Browse files Browse the repository at this point in the history
  • Loading branch information
ziishaned committed Apr 2, 2017
1 parent b53b062 commit bbbb805
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
40 changes: 39 additions & 1 deletion database/seeds/Components/Wiki/WikisTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,55 @@

namespace Database\Seeds\Components\Wiki;

use Carbon\Carbon;
use App\Models\Wiki;
use Illuminate\Database\Seeder;

/**
* @author Zeeshan Ahmed <[email protected]>
*/
class WikisTableSeeder extends Seeder
{
/**
* Path to wikis.json file.
*
* @var string
*/
private $wikisFilePath = 'database\seeds\Components\Wiki\wikis.json';

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
$wikis = $this->getWikis();

foreach ($wikis as $wiki) {
Wiki::insert([
'name' => $wiki['name'],
'slug' => str_slug($wiki['name'], '_'),
'outline' => $wiki['outline'],
'description' => $wiki['description'],
'user_id' => $wiki['user_id'],
'space_id' => $wiki['space_id'],
'team_id' => $wiki['team_id'],
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
]);
}
}

/**
* Get the wikis from json file.
*
* @return array $wikis
*/
private function getWikis()
{
$wikis = file_get_contents(base_path($this->wikisFilePath));

return json_decode($wikis, true);
}
}
File renamed without changes.
6 changes: 5 additions & 1 deletion database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Models\Wiki;
use App\Models\Page;
use App\Models\User;
use App\Models\Role;
Expand All @@ -14,6 +15,7 @@
use Database\Seeds\Components\Role\RolesTableSeeder;
use Database\Seeds\Components\Team\TeamsTableSeeder;
use Database\Seeds\Components\User\UsersTableSeeder;
use Database\Seeds\Components\Wiki\WikisTableSeeder;
use Database\Seeds\Components\Team\InvitesTableSeeder;
use Database\Seeds\Components\Space\SpacesTableSeeder;
use Database\Seeds\Components\User\UsersRolesTableSeeder;
Expand All @@ -30,14 +32,15 @@ class DatabaseSeeder extends Seeder
PagesTableSeeder::class,
TeamsTableSeeder::class,
UsersTableSeeder::class,
WikisTableSeeder::class,
SpacesTableSeeder::class,
InvitesTableSeeder::class,
UsersTeamsTableSeeder::class,
UsersRolesTableSeeder::class,
PermissionsTableSeeder::class,
RolePermissionsTableSeeder::class,
IntegrationActionsTableSeeder::class,
NotificationCategoryTableSeeder::class,
NotificationCategoryTableSeeder::class
];


Expand Down Expand Up @@ -65,6 +68,7 @@ private function emptyModels()
{
Page::getQuery()->delete();
Role::getQuery()->delete();
Wiki::getQuery()->delete();
Team::getQuery()->delete();
User::getQuery()->delete();
Space::getQuery()->delete();
Expand Down

0 comments on commit bbbb805

Please sign in to comment.