if (is_array($field)) {
$field = Field::getInstance($field);
}
+ if (!$field->getAttribute('fillable', true)) {
+ $field->setAttribute('type','hidden');
+ $field->setAttribute('type','hidden');
+ }
/** @var $field Field */
if ($field->isDisplayColumn()) {
$this->crud->addColumn($field->getColumnData());
namespace Cubist\Backpack\app\Magic\Fields;
use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Cubist\Backpack\CubistBackpackServiceProvider;
use Doctrine\DBAL\Schema\Table;
use Exception;
use Illuminate\Support\Str;
protected $_translatable = false;
protected $_migrateTranslatable = false;
+ protected $_can = null;
+ protected $_auth = true;
+
/**
* @var CubistMagicAbstractModel
*/
'column_type' => $this->_columnType, 'column_move_after' => $this->_columnMoveAfter,
'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
'allow_null' => true,
+ 'can' => $this->_can, 'auth' => $this->_auth,
'fake' => false, 'store_in' => 'extras', 'attributes' => []];
}
$wrapperAttributes['data-when'] = json_encode($this->getAttribute('when'));
$this->setAttribute('wrapperAttributes', $wrapperAttributes);
}
+
+ if (null !== $this->getAttribute('can', null)) {
+ if (!can($this->getAttribute('can'))) {
+ $this->setAttribute('auth', false);
+ $this->setAttribute('type', 'authhidden');
+ $this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
+ }
+ }
}
/**
/** @var \Illuminate\Database\Eloquent\Model $inst */
$inst = new $modelClass();
- $attr=$this->getAttribute('attribute');
- return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getKey())->toArray();
+ $attr = $this->getAttribute('attribute');
+ return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getKeyName())->toArray();
}
public function getDatabaseType()
class User extends SelectFromModel
{
protected $_optionsmodel = '\App\User';
- protected $_allows_null = true;
+ protected $_allows_null = false;
public function getDefaultAttributes()
{
- $default=['optionsmodel' => $this->_optionsmodel];
-
- $auth=auth();
- if($auth){
- $user=$auth->user();
- if($user){
- $default['value']=$user->id;
+ $default = ['optionsmodel' => $this->_optionsmodel, 'attribute' => 'name'];
+ $auth = auth();
+ if ($auth) {
+ $user = $auth->user();
+ if ($user) {
+ $default['value'] = $user->id;
}
}
return array_merge(parent::getDefaultAttributes(), $default);
return base_path('protected/' . $path);
}
}
+
+if (!function_exists('can')) {
+ function can($permission, $model = null)
+ {
+ return auth()->user()->can($permission, $model = null);
+ }
+}