protected function __getOptions()
{
$modelClass = $this->getAttribute('optionsmodel');
+ /** @var \Illuminate\Database\Eloquent\Model $inst */
$inst = new $modelClass();
$attr=$this->getAttribute('attribute');
- return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getPrimaryKey())->toArray();
+ return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getKey())->toArray();
}
public function getDatabaseType()
<?php
-
namespace Cubist\Backpack\app\Magic\Fields;
class User extends SelectFromModel
{
protected $_optionsmodel = '\App\User';
+ protected $_allows_null = true;
public function getDefaultAttributes()
{
- return array_merge(parent::getDefaultAttributes(), ['optionsmodel' => $this->_optionsmodel]);
+ $default=['optionsmodel' => $this->_optionsmodel];
+
+ $auth=auth();
+ if($auth){
+ $user=$auth->user();
+ if($user){
+ $default['value']=$user->id;
+ }
+ }
+ return array_merge(parent::getDefaultAttributes(), $default);
}
}