forked from doppar/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateSeedCommand.php
More file actions
77 lines (64 loc) · 1.64 KB
/
CreateSeedCommand.php
File metadata and controls
77 lines (64 loc) · 1.64 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Phaseolies\Console\Commands\Migrations;
use Phaseolies\Console\Schedule\Command;
class CreateSeedCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:seeder {name}';
/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Creates a new seeder class.';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$filePath = base_path('database/seeders/' . $name . '.php');
if (file_exists($filePath)) {
$this->displayError('Seed file already exists!');
return Command::FAILURE;
}
$content = $this->generateSeedContent($name);
file_put_contents($filePath, $content);
$this->displaySuccess('Seed file created successfully');
$this->line("<fg=yellow>📁 File:</> <fg=white>{$filePath}</>");
return Command::SUCCESS;
});
}
/**
* Generate the content for the seeder class.
*
* @param string \$className
* @return string
*/
protected function generateSeedContent(string $className): string
{
return <<<EOT
<?php
namespace Database\Seeders;
use Phaseolies\Database\Migration\Seeder;
class {$className} extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run(): void
{
}
}
EOT;
}
}