-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabaseSeedCommand.php
More file actions
executable file
·41 lines (30 loc) · 1.23 KB
/
DatabaseSeedCommand.php
File metadata and controls
executable file
·41 lines (30 loc) · 1.23 KB
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
<?php
namespace Leaf\Commands;
use Leaf\Sprout\Command;
class DatabaseSeedCommand extends Command
{
protected $signature = 'db:seed
{file? : The name of the schema file to seed}';
protected $description = 'Seed the database with records';
protected $help = 'Seed the database with records';
protected function handle()
{
$fileToSeed = $this->argument('file');
$seeds = function_exists('AppPaths') ?
glob(getcwd() . DIRECTORY_SEPARATOR . AppPaths('database') . DIRECTORY_SEPARATOR . '*.yml') :
glob(getcwd() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . '*.yml');
foreach ($seeds as $seed) {
$currentFileName = path($seed)->basename();
if ($fileToSeed && preg_replace('/\.yml$/', '', $currentFileName) !== preg_replace('/\.yml$/', '', $fileToSeed)) {
continue;
}
if (!\Leaf\Schema::seed($seed)) {
$this->error("Could not seed $currentFileName");
return 1;
}
$this->writeln("> $currentFileName seeded successfully!");
}
$this->info("Database seeding completed!\n");
return 0;
}
}