Exemplo n.º 1
0
 public function save()
 {
     $class = CrudModel::resolveClass($this->config['model']);
     $titles = $this->model->getApp()['request']->get($this->config['name'] . '_title');
     foreach ($this->dirtyValue as $idx => $file) {
         if ($file instanceof UploadedFile) {
             $obj = new $class();
             $fileInfo = $obj->attachStoreTmpFile($file);
             $fileInfo['title'] = $titles[$idx] ?? $fileInfo['originalName'];
             if (!empty($fileInfo['originalPath'])) {
                 $obj->setAttribute($this->relation->getForeignKey(), $this->model->getKey());
                 $obj->attachStoreFile($fileInfo, $this->model->getFilesConfig($fileInfo['originalName']));
             }
         }
     }
     $titles = $this->model->getApp()['request']->get($this->config['name'] . '_title');
     if ($titles && !empty($titles)) {
         foreach ($titles as $iid => $title) {
             if ($iid > 0) {
                 $obj = $class::findOrFail($iid);
                 $obj->title = $title;
                 $obj->save();
             }
         }
     }
 }
Exemplo n.º 2
0
 public function create()
 {
     $table = $this->config['pivot_table'] ?? null;
     $self = $this->config['pivot_self_key'] ?? null;
     $foreign = $this->config['pivot_foreign_key'] ?? null;
     $this->relation = $this->model->belongsToMany(CrudModel::resolveClass($this->config['model']), $table, $self, $foreign, $this->config['name']);
     $this->sort();
     return $this;
 }
Exemplo n.º 3
0
 public function save()
 {
     $class = CrudModel::resolveClass($this->config['model']);
     if ($this->dirtyValue instanceof UploadedFile) {
         $obj = $class::findOrNew($this->model->getAttribute($this->config['field']));
         $fileInfo = $obj->attachStoreTmpFile($this->dirtyValue);
         if (!empty($fileInfo['originalPath'])) {
             $obj->attachStoreFile($fileInfo, $this->model->getFilesConfig($fileInfo['originalName']));
             $this->model->setAttribute($this->relation->getForeignKey(), $obj->getKey());
             $this->model->save();
         }
     }
 }
Exemplo n.º 4
0
 public function create()
 {
     $this->relation = $this->model->morphMany(CrudModel::resolveClass($this->config['model']), $this->config['name'], $this->config['field_ref_class'], $this->config['field_ref_id']);
     $this->sort();
     return $this;
 }
Exemplo n.º 5
0
 public function create()
 {
     $this->relation = $this->model->hasMany(CrudModel::resolveClass($this->config['model']), $this->config['field'] ?? null);
     $this->sort();
     return $this;
 }
Exemplo n.º 6
0
 public function create()
 {
     $this->relation = $this->model->belongsTo(CrudModel::resolveClass($this->config['model']), $this->config['field'], null, $this->config['name']);
     return $this;
 }