initDatabase(); $this->initAdminDirectory(); } /** * Create tables and seed it. * * @return void */ public function initDatabase() { $this->call('migrate'); $userModel = config('admin.database.users_model'); if ($userModel::count() == 0) { $this->call('db:seed', ['--class' => \Dcat\Admin\Models\AdminTablesSeeder::class]); } } /** * Initialize the admAin directory. * * @return void */ protected function initAdminDirectory() { $this->directory = config('admin.directory'); if (is_dir($this->directory)) { $this->line("{$this->directory} directory already exists ! "); return; } $this->makeDir('/'); $this->line('Admin directory was created: '.str_replace(base_path(), '', $this->directory)); $this->makeDir('Controllers'); $this->createHomeController(); $this->createAuthController(); $this->createBootstrapFile(); $this->createRoutesFile(); } /** * Create HomeController. * * @return void */ public function createHomeController() { $homeController = $this->directory.'/Controllers/HomeController.php'; $contents = $this->getStub('HomeController'); $this->laravel['files']->put( $homeController, str_replace('DummyNamespace', config('admin.route.namespace'), $contents) ); $this->line('HomeController file was created: '.str_replace(base_path(), '', $homeController)); } /** * Create AuthController. * * @return void */ public function createAuthController() { $authController = $this->directory.'/Controllers/AuthController.php'; $contents = $this->getStub('AuthController'); $this->laravel['files']->put( $authController, str_replace('DummyNamespace', config('admin.route.namespace'), $contents) ); $this->line('AuthController file was created: '.str_replace(base_path(), '', $authController)); } /** * Create routes file. * * @return void */ protected function createBootstrapFile() { $file = $this->directory.'/bootstrap.php'; $contents = $this->getStub('bootstrap'); $this->laravel['files']->put($file, $contents); $this->line('Bootstrap file was created: '.str_replace(base_path(), '', $file)); } /** * Create routes file. * * @return void */ protected function createRoutesFile() { $file = $this->directory.'/routes.php'; $contents = $this->getStub('routes'); $this->laravel['files']->put($file, str_replace('DummyNamespace', config('admin.route.namespace'), $contents)); $this->line('Routes file was created: '.str_replace(base_path(), '', $file)); } /** * Get stub contents. * * @param $name * * @return string */ protected function getStub($name) { return $this->laravel['files']->get(__DIR__."/stubs/$name.stub"); } /** * Make new directory. * * @param string $path */ protected function makeDir($path = '') { $this->laravel['files']->makeDirectory("{$this->directory}/$path", 0755, true, true); } }