|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelZero\Framework\Commands\Component\Illuminate\Database; |
|
4
|
|
|
|
|
5
|
|
|
use LaravelZero\Framework\Commands\Component\Installer as BaseInstaller; |
|
6
|
|
|
use LaravelZero\Framework\Contracts\Commands\Component\Installer as InstallerContract; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This is the Laravel Zero Framework illuminate/database install class. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Nuno Maduro <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Installer extends BaseInstaller implements InstallerContract |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $name = 'install:database'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Installs illuminate/database - Eloquent'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The config file path. |
|
27
|
|
|
*/ |
|
28
|
|
|
const CONFIG_FILE = __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'database.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
4 |
|
public function getComponentName(): string |
|
34
|
|
|
{ |
|
35
|
4 |
|
return 'database'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
4 |
|
public function install(): bool |
|
42
|
|
|
{ |
|
43
|
4 |
|
$this->require('illuminate/database "5.5.*"'); |
|
44
|
4 |
|
$this->task( |
|
45
|
4 |
|
'Creating directories and files under database folder', |
|
46
|
4 |
|
function () { |
|
47
|
4 |
|
$this->files->makeDirectory(database_path('migrations'), 0755, true, true); |
|
48
|
4 |
|
if (! $this->files->exists(database_path('database.sqlite'))) { |
|
49
|
4 |
|
$this->files->put(database_path('database.sqlite'), ''); |
|
50
|
|
|
} |
|
51
|
4 |
|
$this->files->makeDirectory(database_path('seeds'), 0755, false, true); |
|
52
|
4 |
|
if (! $this->files->exists(database_path('seeds').DIRECTORY_SEPARATOR.'DatabaseSeeder.php')) { |
|
53
|
4 |
|
$this->files->copy( |
|
54
|
4 |
|
__DIR__.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php', |
|
55
|
4 |
|
database_path('seeds').DIRECTORY_SEPARATOR.'DatabaseSeeder.php' |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
4 |
|
return true; |
|
60
|
4 |
|
} |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
4 |
|
$this->task( |
|
64
|
4 |
|
'Creating default config', |
|
65
|
4 |
|
function () { |
|
66
|
4 |
|
if (! $this->files->exists(config_path('database.php'))) { |
|
67
|
4 |
|
$this->files->copy( |
|
68
|
4 |
|
static::CONFIG_FILE, |
|
69
|
4 |
|
config_path('database.php') |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
4 |
|
return true; |
|
74
|
4 |
|
} |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
4 |
|
$this->info('Usage:'); |
|
78
|
4 |
|
$this->comment( |
|
79
|
4 |
|
' |
|
80
|
|
|
|
|
81
|
|
|
$ php <your-application-name> make:migration create_users_table |
|
82
|
|
|
$ php <your-application-name> migrate |
|
83
|
|
|
|
|
84
|
|
|
use Illuminate\Support\Facades\DB; |
|
85
|
|
|
|
|
86
|
|
|
DB::table(\'users\')->insert( |
|
87
|
|
|
[\'email\' => \'[email protected]\'] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$users = DB::table(\'users\')->get(); |
|
91
|
|
|
|
|
92
|
|
|
dd($users); |
|
93
|
|
|
|
|
94
|
|
|
' |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
4 |
|
return true; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|