*/
protected $description = 'Generate Controllers, Requests, Routes, migrations according to magic';
+ /**
+ * @var array
+ */
+ protected $_routes = [];
+
/**
* Execute the console command.
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);
}
$route = $model->getOption('route', $model->getOption('name'));
$controller = $model->getControllerClass();
+
+ $this->_routes[] = ' Route::crud(\'' . $route . '\', \'' . $controller . '\');';
}
}
{
public function __construct()
{
- if (!$this->crud) {
+ if ($this->crud) {
+ return;
+ }
+
+ // call the setup function inside this closure to also have the request there
+ // this way, developers can use things stored in session (auth variables, etc)
+ $this->middleware(function ($request, $next) {
+ // make a new CrudPanel object, from the one stored in Laravel's service container
$this->crud = app()->make(CubistCrudPanel::class);
+ // ensure crud has the latest request
+ $this->crud->setRequest($request);
+ $this->request = $request;
+ $this->setupDefaults();
+ $this->setup();
+ $this->setupConfigurationForCurrentOperation();
- // call the setup function inside this closure to also have the request there
- // this way, developers can use things stored in session (auth variables, etc)
- $this->middleware(function ($request, $next) {
- $this->request = $request;
- $this->crud->request = $request;
- $this->setup();
+ return $next($request);
+ });
- return $next($request);
- });
- }
+ parent::__construct();
}
}
class CubistMagicController extends CubistCrudController
{
- use CrudTrait;
use HandleAjaxMedia;
use ListOperation;
protected $_oneInstance;
protected $_nested = false;
- public function __construct()
- {
- parent::__construct();
- }
-
// Routes
//Route::post($this->name . '/bulk-publish', [
////'as' => 'crud.' . $this->name . '.bulkPublish',
}
- $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
+ $this->crud->setRoute(backpack_url($this->_routeURL));
$this->crud->setEntityNameStrings($this->_singular, $this->_plural);
$this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
$this->updateFieldsFromModel($model);
-
- $this->setupRoutes($this->_routeURL, $this->_routeURL, $this->_routeURL);
-
}
public function updateFieldsFromModel($model = null)
$this->_forgetCache();
parent::saveReorder();
}
+
+ public function setupListOperation()
+ {
+ echo ":)";
+ }
+
+ public function setupCreateOperation()
+ {
+ echo ":)";
+ }
+
+ public function setupUpdateOperation()
+ {
+ echo ":)";
+ }
+
}
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace' => 'App\Http\Controllers\Admin',
], function () { // custom admin routes
-
+ _CUSTOM_
});