]> _ Git - cubist_cms-back.git/commitdiff
wip #3466 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 4 Mar 2020 19:00:28 +0000 (20:00 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 4 Mar 2020 19:00:28 +0000 (20:00 +0100)
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/User.php

index feec9cb75c1d9d39dabbd812cb017776f9487e05..6bf73f081c6bc98d1c78d3b6642b2018cfc0fc1e 100644 (file)
@@ -26,10 +26,11 @@ class Model extends Field
     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()
index 372888f1ccf546f9e6fe3575da7d2c98aec69daa..af342c32d4151b3a510c7c8d4c3598b4a864840c 100644 (file)
@@ -1,14 +1,23 @@
 <?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);
     }
 }