use Backpack\CRUD\app\Http\Controllers\CrudController;
-use Cubist\Backpack\Http\Controllers\Operations\ListOperation;
use Cubist\Backpack\Http\Controllers\Operations\MediaOperation;
+use Cubist\Backpack\Magic\Operations\ListOperation;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class CubistCrudController extends CrudController
+++ /dev/null
-<?php
-
-
-namespace Cubist\Backpack\Http\Controllers\Operations;
-
-
-trait ListOperation
-{
- use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation {
- index as baseIndex;
- }
-
- protected function index()
- {
- $this->getModelInstance()->addWidgets();
- return $this->baseIndex();
- }
-}
}
}
- public function index()
- {
- if ($this->_oneInstance) {
- return Redirect::to(backpack_url($this->_routeURL . '/1/edit'));
- }
- return parent::index();
- }
-
- public function edit($id)
- {
- if ($this->_oneInstance) {
- $id = 1;
- }
- $this->getModelInstance()->onBeforeEdit($this, $id);
- return parent::edit($id);
- }
-
- public function create()
- {
- $this->getModelInstance()->onBeforeCreate($this);
- return parent::create();
- }
-
protected function _bulkChangeOnlineStatus($status)
{
$this->crud->hasAccessOrFail('update');
protected $_databaseType = 'text';
protected $_databaseUnique = false;
protected $_databaseIndex = false;
+ protected $_databaseDefault = null;
/** @var bool|string|array */
protected $_cast = false;
return 'text';
}
}
- return $this->_databaseType;
+ return $this->getAttribute('database_type');
}
'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
'allow_null' => true,
'can' => $this->_can, 'can_write' => $this->_canWrite, 'auth' => $this->_auth,
- 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex,
+ 'database_type' => $this->_databaseType, 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex, 'database_default' => $this->_databaseDefault,
'fake' => false, 'store_in' => 'extras', 'attributes' => []];
}
return;
}
+
$attributes = array_merge(
['notnull' => !$this->getAttribute('allow_null', true)],
$this->_databaseAttributes
);
+ if ($this->getAttribute('database_default') !== null) {
+ $attributes['default'] = $this->getAttribute('database_default');
+ }
+
$table->addColumn($name,
CubistMagicAbstractModel::toDoctrineType($this->getDatabaseType()),
$attributes
);
+
if ($this->getAttribute('database_unique', false)) {
$table->addUniqueIndex([$name]);
}
public static function boot()
{
parent::boot();
+
static::addGlobalScope('ownerclause', function (Builder $builder) {
static::addOwnerClause($builder);
});
}
+
+ /*
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @return void
+ */
+ public function scopeCreatedok($query)
+ {
+ $query->where('created_ok', 1);
+ }
+
public static function addOwnerClause(Builder $builder)
{
}
'hidden' => true,
'fillable' => false]);
}
+ $this->addField(
+ ['name' => 'created_ok',
+ 'type' => 'Hidden',
+ 'default' => '1',
+ 'database_default' => '1',
+ 'database_type' => 'boolean',
+ 'translatable' => false,
+ 'value' => '1',
+ 'hidden' => true,
+ 'fillable' => false]
+ );
$this->fakeColumns = array_unique($this->fakeColumns);
if (get_class($this) !== config("auth.providers.users.model")) {
}
- /**
- * @param $user CubistMagicAuthenticatable
- * @return bool
- */
+ /**
+ * @param $user CubistMagicAuthenticatable
+ * @return bool
+ */
public function canView($user)
{
return $this->canList($user);
<?php
namespace Cubist\Backpack\Magic\Operations;
+
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
trait CreateOperation
{
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation {
store as _store;
+ create as _create;
setupCreateDefaults as _setupCreateDefaults;
}
+ /**
+ * Show the form for creating inserting a new row.
+ *
+ * @return \Illuminate\Contracts\View\View
+ */
+ public function create()
+ {
+ $instance = $this->crud->model;
+ if ($instance instanceof CubistMagicAbstractModel) {
+ $instance->setAttribute('created_ok', '0');
+ $instance->saveQuietly();
+ $id = $instance->getIdValue();
+ return redirect(backpack_url($instance->getOption('name') . '/' . $id . '/edit'));
+ }
+ return $this->_create();
+ }
+
public function store()
{
$res = $this->_store();
- if($this->crud->entry instanceof CubistMagicAbstractModel) {
+ if ($this->crud->entry instanceof CubistMagicAbstractModel) {
$this->crud->entry->onAfterSave();
}
return $res;
--- /dev/null
+<?php
+
+namespace Cubist\Backpack\Magic\Operations;
+
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+
+trait ListOperation
+{
+ use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation {
+ search as _search;
+ index as _index;
+ }
+
+ public function index()
+ {
+ $this->getModelInstance()->addWidgets();
+ $this->crud->addClause('createdok');
+ return $this->_index();
+ }
+
+ public function search()
+ {
+ $this->crud->addClause('createdok');
+ return $this->_search();
+ }
+
+
+}
setupUpdateDefaults as _setupUpdateDefaults;
}
-
/**
* Update the specified resource in the database.
*