mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 22:52:32 +01:00
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\User;
|
|
use Illuminate\Console\Command;
|
|
|
|
class DB extends Command {
|
|
|
|
protected $signature = 'flox:db {username?} {password?}';
|
|
protected $description = 'Create database migrations and admin account';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
try {
|
|
$this->createMigrations();
|
|
} catch(\Exception $e) {
|
|
$this->error('Can not connect to the database. Error: ' . $e->getMessage());
|
|
$this->error('Make sure your database credentials in .env are correct');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->createUser();
|
|
}
|
|
|
|
private function createMigrations()
|
|
{
|
|
$this->info('TRYING TO MIGRATE DATABASE');
|
|
$this->call('migrate', ['--force' => true]);
|
|
$this->info('MIGRATION COMPLETED');
|
|
}
|
|
|
|
private function createUser()
|
|
{
|
|
$username = $this->ask('Enter your admin username', $this->argument("username"));
|
|
$password = $this->ask('Enter your admin password', $this->argument("password"));
|
|
|
|
$user = new User();
|
|
$user->username = $username;
|
|
$user->password = bcrypt($password);
|
|
$user->save();
|
|
}
|
|
}
|