namespace Cubist\Backpack\app\Console\Commands;
use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Util;
use Cubist\Util\Files\Files;
use Cubist\Util\PHP;
use Illuminate\Console\Command;
*/
protected $description = 'Generate Controllers, Requests, Routes, migrations according to magic';
+ protected $_routes = [];
+
/**
* Execute the console command.
*
} else {
$this->line('No magic folder at ' . $magic);
}
+ $this->_writeRoutes();
$this->executeProcess('composer dump-autoload');
}
+ protected function _writeRoutes()
+ {
+ $routesDir = base_path() . '/routes/backpack';
+ if (!file_exists($routesDir)) {
+ mkdir($routesDir, 0777, true);
+ }
+ $stub = file_get_contents(Util::getStubPath() . '/routes.stub');
+ $stub = str_replace('_CUSTOM_', implode("\n", $this->_routes), $stub);
+
+ file_put_contents($routesDir . '/custom.php', $stub);
+ }
+
protected function _handleMagicFolder($folder)
{
$this->line('Handling folder ' . $folder);
if ($class instanceof CubistMagicModelAbstract) {
$this->line('Generate code of ' . get_class($class));
$class->generateCode();
+ $this->_routes[] = 'CRUD::resource(\'' . $class->getOption('name') . '\', \'' . $class->getControllerClass() . '\');';
}
} catch (\Exception $e) {
}
}
+
}
/**
namespace Cubist\Backpack\app\Magic\Models;
use Cubist\Backpack\app\Magic\Fields\CubistMagicField;
+use Cubist\Backpack\app\Magic\Util;
use Illuminate\Database\Eloquent\Model;
use Cubist\Backpack\app\Magic\CubistMagicAttribute;
use Illuminate\Support\Facades\Route;
$this->_fields[$field->getAttribute('name')] = $field;
}
- public function loadRoute()
- {
- Route::group([
- 'prefix' => config('backpack.base.route_prefix', 'admin'),
- 'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
- 'namespace' => 'Cubist\Backpack\app\Http\Controllers',
- ], function () { // custom admin routes
- CRUD::resource('model', 'CubistModelCrudController');
- CRUD::resource('model', 'CubistModelCrudController');
- }); // this should be the absolute last line of this file
- }
-
public function generateCode()
{
$this->_generateControllerCode();
protected function _generateControllerCode()
{
- $this->_replaceInCode($this->_getStubPath() . 'Controller.stub',
- app_path() . '/Http/Controllers/Admin/' . $this->getStudlyName() . 'Controller.php');
+ $this->_replaceInCode(Util::getStubPath() . 'Controller.stub',
+ app_path() . '/Http/Controllers/Admin/' . $this->getControllerClass() . '.php');
}
+ public function getControllerClass()
+ {
+ return $this->getStudlyName() . 'CrudController';
+ }
protected function _replaceInCode($stub, $dest)
{
- $vars = ['STUDLYNAME' => $this->getStudlyName(),
+ $vars = ['CONTROLLERCLASS' => $this->getControllerClass(),
'ROUTEURL' => $this->getOption('name'),
'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
'PLURAL' => $this->getOption('plural', ''),
return $res;
}
- protected function _getStubPath()
- {
- return __DIR__ . '/../../../resources/cubistmagic/';
- }
public function getStudlyName()
{
--- /dev/null
+<?php
+
+namespace Cubist\Backpack\app\Magic;
+
+
+class Util
+{
+ public static function getStubPath()
+ {
+ return __DIR__ . '/../../../resources/cubistmagic/';
+ }
+}
namespace App\Htpp\Controllers\Admin;
use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
-class _STUDLYNAME_Controller extends CubistMagicController
+class _CONTROLLERCLASS_ extends CubistMagicController
{
protected $_modelNamespace = '_MODELNAMESPACE_';
protected $_routeURL = '_ROUTEURL_';
--- /dev/null
+<?php
+Route::group([
+ 'prefix' => config('backpack.base.route_prefix', 'admin'),
+ 'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
+ 'namespace' => 'App\Http\Controllers\Admin',
+], function () { // custom admin routes
+ _CUSTOM_
+}); // this should be the absolute last line of this file