diff --git a/database/seeds/Components/Wiki/WikisTableSeeder.php b/database/seeds/Components/Wiki/WikisTableSeeder.php index 0ba0ed46..9d745b70 100644 --- a/database/seeds/Components/Wiki/WikisTableSeeder.php +++ b/database/seeds/Components/Wiki/WikisTableSeeder.php @@ -2,10 +2,22 @@ namespace Database\Seeds\Components\Wiki; +use Carbon\Carbon; +use App\Models\Wiki; use Illuminate\Database\Seeder; +/** + * @author Zeeshan Ahmed + */ class WikisTableSeeder extends Seeder { + /** + * Path to wikis.json file. + * + * @var string + */ + private $wikisFilePath = 'database\seeds\Components\Wiki\wikis.json'; + /** * Run the database seeds. * @@ -13,6 +25,32 @@ class WikisTableSeeder extends Seeder */ 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); } } diff --git a/database/seeds/Components/Wiki/wiki.json b/database/seeds/Components/Wiki/wikis.json similarity index 100% rename from database/seeds/Components/Wiki/wiki.json rename to database/seeds/Components/Wiki/wikis.json diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index d952e95e..94f0c328 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -1,5 +1,6 @@ delete(); Role::getQuery()->delete(); + Wiki::getQuery()->delete(); Team::getQuery()->delete(); User::getQuery()->delete(); Space::getQuery()->delete();