1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\AdminLTETemplateLaravel\Console; |
4
|
|
|
|
5
|
|
|
use Acacha\AdminLTETemplateLaravel\Compiler\StubFileCompiler; |
6
|
|
|
use Acacha\AdminLTETemplateLaravel\Filesystem\Filesystem; |
7
|
|
|
use Illuminate\Console\Command; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MakeAdminUserSeeder. |
11
|
|
|
* |
12
|
|
|
* @package Acacha\AdminLTETemplateLaravel\Console |
13
|
|
|
*/ |
14
|
|
|
class MakeAdminUserSeeder extends Command |
15
|
|
|
{ |
16
|
|
|
use HasUsername, HasEmail; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The name and signature of the console command. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $signature = 'make:adminUserSeeder'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Create a new seed to add admin user to database'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Filesystem. |
34
|
|
|
* |
35
|
|
|
* @var Filesystem |
36
|
|
|
*/ |
37
|
|
|
protected $filesystem; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Compiler for stub file. |
41
|
|
|
* |
42
|
|
|
* @var StubFileCompiler |
43
|
|
|
*/ |
44
|
|
|
protected $compiler; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create a new command instance. |
48
|
|
|
* |
49
|
|
|
* @param Filesystem $filesystem |
50
|
|
|
* @param StubFileCompiler $compiler |
51
|
|
|
*/ |
52
|
|
|
public function __construct(Filesystem $filesystem, StubFileCompiler $compiler) |
53
|
|
|
{ |
54
|
|
|
parent::__construct(); |
55
|
|
|
$this->filesystem = $filesystem; |
56
|
|
|
$this->compiler = $compiler; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Execute the console command. |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function handle() |
64
|
|
|
{ |
65
|
|
|
try { |
66
|
|
|
$this->filesystem->overwrite( |
67
|
|
|
$path = database_path('seeds/' . config('AdminUserSeeder','AdminUserSeeder.php')), |
68
|
|
|
$this->compiler->compile( |
69
|
|
|
$this->filesystem->get($this->getStubPath()), |
70
|
|
|
[ |
71
|
|
|
"USER_NAME" => $this->username(), |
72
|
|
|
"USER_EMAIL" => $this->email(), |
73
|
|
|
])); |
74
|
|
|
$this->info('File ' . $path . ' created'); |
75
|
|
|
} catch (\Exception $e) { |
76
|
|
|
print_r($e->getMessage()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get path to stub. |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
protected function getStubPath() { |
86
|
|
|
return __DIR__ . '/stubs/AdminUserSeeder.php.stub'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|