1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\AdminLTETemplateLaravel\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AdminLTEAdmin. |
9
|
|
|
*/ |
10
|
|
|
class AdminLTEAdmin extends Command |
11
|
|
|
{ |
12
|
|
|
use HasUsername, HasEmail; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
*/ |
17
|
|
|
protected $signature = 'adminlte-laravel:admin'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Create a seed for admin user and execute seed'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Execute the console command. |
28
|
|
|
*/ |
29
|
|
|
public function handle() |
30
|
|
|
{ |
31
|
|
|
$this->create_admin_user(); |
32
|
|
|
$this->info('User ' . $this->username() . '(' . $this->email() . ') ' . |
33
|
|
|
$this->passwordInfo() . ' created succesfully!'); |
34
|
|
|
$this->call('make:adminUserSeeder'); |
35
|
|
|
$this->info('A database seed has been created to permanently add admin user to database.'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create admin user. |
40
|
|
|
*/ |
41
|
|
|
protected function create_admin_user() |
42
|
|
|
{ |
43
|
|
|
try { |
44
|
|
|
factory(App\User::class)->create([ |
45
|
|
|
"name" => env('ADMIN_USER', $this->username()), |
46
|
|
|
"email" => env('ADMIN_EMAIL', $this->email()), |
47
|
|
|
"password" => bcrypt(env('ADMIN_PWD', '123456'))] |
48
|
|
|
); |
49
|
|
|
} catch (\Illuminate\Database\QueryException $exception) { |
|
|
|
|
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get password info. |
56
|
|
|
*/ |
57
|
|
|
protected function passwordInfo() |
58
|
|
|
{ |
59
|
|
|
if (env('ADMIN_PWD', '123456') == '123456') { |
60
|
|
|
return 'with password 123456'; |
61
|
|
|
} |
62
|
|
|
return 'with the environemnt password (env var ADMIN_PWD)'; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|