save() public method

Save the model to the database.
public save ( array $options = [] ) : boolean
$options array
return boolean
Example #1
1
 public function updated(Model $model)
 {
     if ($model->isDirty('parent_id')) {
         /**
          * 同步Original数据,是為了清除parent_id的dirty狀態
          */
         $model->syncOriginal();
         $tableName = $model->getTable();
         $oldNode = $model->getOriginal('node');
         if (0 < $model->parent_id) {
             /**
              * @var Model  $parent
              */
             $parent = $model->find($model->parent_id);
             $model->node = $parent->node . $model->id . self::SEPARATOR;
             $model->save();
             //取出原来的level
             $originalLevel = Cache::pull('node-category-original-level-' . $model->id);
             //计算新level与原来的level的差值
             $i = $model->level - $originalLevel;
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level + {$i}"), 'node' => DB::raw("REPLACE(`node`, '{$oldNode}', '{$model->node}')")]);
         } else {
             //修改為頂級分類
             $model->level = 1;
             $model->node = self::SEPARATOR . $model->id . self::SEPARATOR;
             $model->save();
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level - {$model->level}"), 'node' => DB::raw("CONCAT('{$model->node}', `id`, ',')")]);
         }
     }
 }
Example #2
1
 /**
  * @param array $data
  * @return bool
  */
 public function insert(array $data = [])
 {
     $this->source->fill($data);
     if ($this->source->save()) {
         return $this->source->getKey();
     }
     return false;
 }
Example #3
1
 /**
  * Removes a model from this relationship type.
  */
 public function remove(Model $model, $sessionKey = null)
 {
     if ($sessionKey === null) {
         $options = $this->parent->getRelationDefinition($this->relationName);
         if (array_get($options, 'delete', false)) {
             $model->delete();
         } else {
             /*
              * Make this model an orphan ;~(
              */
             $model->setAttribute($this->getPlainForeignKey(), null);
             $model->setAttribute($this->getPlainMorphType(), null);
             $model->save();
         }
         /*
          * Use the opportunity to set the relation in memory
          */
         if ($this instanceof MorphOne) {
             $this->parent->setRelation($this->relationName, null);
         } else {
             $this->parent->reloadRelations($this->relationName);
         }
     } else {
         $this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
     }
 }
Example #4
0
 /**
  * Delete this customer credit card in the billing gateway.
  *
  * @return Creditcard
  */
 public function delete()
 {
     if (!$this->model->readyForBilling()) {
         return $this;
     }
     $this->card->delete();
     $cards = array();
     foreach ($this->model->billing_cards as $c) {
         if (Arr::get($c, 'id') != $this->id) {
             $cards[] = $c;
         }
     }
     $this->model->billing_cards = $cards;
     $this->model->save();
     // Refresh all subscription records that referenced this card.
     if ($subscriptions = $this->model->subscriptionModelsArray()) {
         foreach ($subscriptions as $subscription) {
             if ($subscription->billingIsActive() && $subscription->billing_card == $this->id) {
                 $subscription->subscription()->refresh();
             }
         }
     }
     $this->info = array('id' => $this->id);
     return $this;
 }
Example #5
0
 public function save(array $options = array())
 {
     if (!$this->isValid()) {
         return false;
     }
     return parent::save($options);
 }
 public function save(Model $model)
 {
     $model->save();
     if ($model->hasUpdatedTags()) {
         //$model->tags()->sync($model->getUpdatedTagIds());
     }
 }
 /**
  * Save a translated model.
  *
  * @param Form $form
  * @param Model $model
  * @return bool
  */
 protected function saveTranslations(Form $form, Model $model)
 {
     foreach ($form->translated() as $language_id => $translation) {
         $model->language($language_id)->fill($translation);
     }
     return $model->save();
 }
Example #8
0
 public function save(array $options = array())
 {
     $filename = $this->createBill($this->course()->getResults());
     $this->amount = $this->course()->getResults()->participantNum;
     $this->filename = $filename;
     parent::save($options);
 }
 /**
  * Creates a new log record using Eloquent.
  *
  * @param Model $model
  *
  * @return bool
  */
 public function createLog(Model $model)
 {
     if ($model->save() && $model->exists) {
         return true;
     }
     return false;
 }
Example #10
0
 /**
  * to create main model
  * 
  * @return boolean
  */
 protected function createMainModel(Model $model)
 {
     $post = $this->picker->getNonMultilangToArray();
     $this->createdMainModel = $model->create($post);
     $this->fireOnCRUD('creating');
     return $this->createdMainModel->save();
 }
Example #11
0
 /**
  * Overriding base save to check first if status is sold and if so, if quantity sold = quantity.
  *
  * @param  array  $options
  * @return bool
  */
 public function save(array $options = [])
 {
     if ($this->product_status == 3) {
         $this->quantity_sold = $this->quantity;
     }
     return parent::save($options);
 }
Example #12
0
 public function save(array $options = array())
 {
     if ($this->validate() && !$this->validationMessages) {
         return parent::save($options);
     }
     return false;
 }
Example #13
0
 /**
  * Store the subscription data locally (not in billing gateway).
  *
  * @param array $properties
  *
  * @return Subscription
  */
 public function storeLocal(array $properties = array())
 {
     // Cancel in billing gateway, if active.
     if ($this->model->billingIsActive()) {
         $trial_ends_at = $this->model->billing_trial_ends_at;
         $this->subscription->cancel(true);
         $this->refresh();
         $this->model->billing_trial_ends_at = $trial_ends_at;
         $this->model->billing_subscription_ends_at = null;
     }
     $this->model->billing_active = 0;
     $this->model->billing_amount = 0;
     $this->model->billing_interval = null;
     $this->model->billing_card = null;
     $this->model->billing_subscription_discounts = null;
     $this->model->billing_free = (int) $this->is_free;
     if ($this->plan) {
         $this->model->billing_plan = $this->plan;
     }
     if (!empty($properties['quantity'])) {
         $this->model->billing_quantity = $properties['quantity'];
     }
     $this->model->billing_trial_ends_at = $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at;
     if (!empty($properties['subscription_ends_at'])) {
         $this->model->billing_subscription_ends_at = $properties['subscription_ends_at'];
         $this->model->billing_trial_ends_at = null;
     }
     $this->model->save();
     return $this;
 }
Example #14
0
 /**
  * Save the model to the database.
  *
  * @param  array  $options
  * @return bool
  */
 public function save(array $options = [])
 {
     $this->xh = Auth::user()->xh;
     $this->czsj = Carbon::now();
     $this->bz = isset($this->bz) ? $this->bz : '';
     return parent::save($options);
 }
Example #15
0
 /**
  * Refresh local model data for this customer.
  *
  * @return Billing
  */
 public function refresh()
 {
     $info = array();
     if ($this->customer) {
         try {
             $info = $this->customer->info();
         } catch (Exception $e) {
         }
     }
     if (!empty($info)) {
         $this->model->billing_id = $this->customer->id();
         $this->model->billing_discounts = $info['discounts'];
         $cards = array();
         foreach ($this->customer->cards() as $card) {
             $cards[] = $card->info();
         }
         $this->model->billing_cards = $cards;
     } else {
         $this->model->billing_id = null;
         $this->model->billing_cards = null;
         $this->model->billing_discounts = null;
     }
     $this->model->save();
     $this->info = $info;
     return $this;
 }
 public function save(array $options = [])
 {
     if (!$this->exists) {
         $this->uid = $this->genNewUID();
     }
     return parent::save($options);
 }
Example #17
0
 public function save(array $options = [])
 {
     if (!$this->exists && !$this->isDirty(static::CREATED_AT)) {
         $this->setCreatedAt($this->freshTimestamp());
     }
     return parent::save($options);
 }
Example #18
0
 public function save(array $options = [])
 {
     if ($this->relation) {
         $this->relation->save();
     }
     parent::save($options);
 }
Example #19
0
 /**
  * Seed the form with defaults that are stored in the session
  *
  * @param Model $model
  * @param CrudController $crudController
  */
 public function onCrudSaved(Model $model, CrudController $crudController)
 {
     $fb = $crudController->getFormBuilder();
     foreach ($fb->getElements() as $name => $element) {
         if (!$element instanceof FileElement) {
             continue;
         }
         if ($model instanceof File) {
             $file = $model;
         } else {
             $file = new File();
         }
         if ($uploaded = Input::file($name)) {
             // Save the file to the disk
             $uploaded->move(storage_path($element->getPath()), $uploaded->getClientOriginalName());
             // Update the file model with metadata
             $file->name = $uploaded->getClientOriginalName();
             $file->extension = $uploaded->getClientOriginalExtension();
             $file->size = $uploaded->getClientSize();
             $file->path = $element->getPath() . '/' . $uploaded->getClientOriginalName();
             $file->save();
             if (!$model instanceof File) {
                 $model->{$name} = $element->getPath() . '/' . $uploaded->getClientOriginalName();
                 $model->save();
             }
         }
     }
 }
 public function created(Model $model)
 {
     if ($model->hashidStrategy() == 'id') {
         $model->generateHashidFromId();
         $model->save();
     }
 }
Example #21
0
 public function save(array $options = array())
 {
     if ($this->autoValidate && !$this->validate()) {
         return false;
     }
     return parent::save($options);
 }
 /**
  * Save the resource in storage.
  *
  * @param  string
  * @return Response
  */
 protected function save($action)
 {
     // Set feedback message depending on action type
     switch ($action) {
         default:
             $successMessage = _('%s successfully saved');
             $errorMessage = _('Unable to save %s');
             break;
         case 'store':
         case '_store':
             $successMessage = _('%s successfully created');
             $errorMessage = _('Unable to create %s');
             break;
         case 'update':
         case '_update':
             $successMessage = _('%s successfully updated');
             $errorMessage = _('Unable to update %s');
             break;
     }
     // Persist to storage
     try {
         if (!$this->resource->save()) {
             throw new DomainException($errorMessage);
         }
         Session::flash('success', sprintf($successMessage, $this->resource));
         return redirect()->route($this->route . '.show', [$this->resource->getKey()]);
     } catch (DomainException $e) {
         Session::flash('error', sprintf($e->getMessage(), $this->resource));
         return redirect()->back()->withInput();
     }
 }
Example #23
0
 public function save(array $option = array())
 {
     if (!$this->checkExist()) {
         return parent::save($option);
     }
     return true;
 }
Example #24
0
 /**
  * 存储操作
  *
  * 存储时尝试先存储 Relation ,再存储 Model ,任一失败则回滚
  *
  * @param array $options
  * @return bool
  */
 public function save($options = []) : bool
 {
     \DB::beginTransaction();
     try {
         $failed = $this->saveRelations() === false || $this->original->save() === false;
         if ($failed) {
             \DB::rollBack();
             return false;
         }
         \DB::commit();
         return true;
     } catch (\Throwable $e) {
         \DB::rollBack();
         return false;
     }
 }
 public function save(array $options = array())
 {
     if ($this->subclassField) {
         $this->attributes[$this->subclassField] = get_class($this);
     }
     parent::save($options);
 }
Example #26
0
 public function save(array $options = array())
 {
     if (!isset($this->id)) {
         $this->ordem = Tarefa::orderBy('ordem', 'DESC')->first()->ordem + 1;
     }
     return parent::save($options);
 }
 /**
  * update data of the eloquent model
  *
  * @param $model
  * @param string|null $path
  * @param boolean $updateRelation
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function updateModel($model, $path = null, $updateRelation = false)
 {
     $this->model = $model;
     DB::beginTransaction();
     try {
         $this->model->fill($this->getData());
         if (!$this->model->save()) {
             throw new UpdateException($this->model);
         }
         // eğer dosya varsa yükle
         if ($this->fileOptions) {
             $this->preUploadFile(UpdateException::class);
         }
         // eğer başka ilişki varsa onları da ekle
         if ($this->opsRelation && !$this->fillModel($this->opsRelation)) {
             throw new UpdateException($this->request->all());
         }
         event(new $this->events['success']($this->model));
         DB::commit();
         if (is_null($path)) {
             return response()->json($this->returnData('success'));
         }
         Flash::success(trans('laravel-modules-base::admin.flash.update_success'));
         return $this->redirectRoute($path, $updateRelation);
         // yeni ilişkili kategoriye göre git
     } catch (UpdateException $e) {
         DB::rollback();
         event(new $this->events['fail']($e->getDatas()));
         if (is_null($path)) {
             return response()->json($this->returnData('error'));
         }
         Flash::error(trans('laravel-modules-base::admin.flash.update_error'));
         return $this->redirectRoute($path);
     }
 }
Example #28
0
 /**
  * However, with normal autoincrement ids - we have to set the slug after
  * the model has been persisted to the database - as then we have the id.
  *
  * @param $model
  */
 public function created(Model $model)
 {
     if ($model->slugStrategy() == 'id') {
         $model->generateIdSlug();
         $model->save();
     }
 }
 /**
  * Template method for updating a record in storage
  * 
  * @param  int $id   
  * @param  array  $fields
  * @return bool       
  */
 public function update($id, array $fields)
 {
     //caching the updated model
     $this->model = $this->findById($id);
     $this->fillData($fields);
     return $this->model->save($fields);
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function save(array $options = array())
 {
     $saved = parent::save($options);
     if ($saved) {
         static::$models[$this->getKey()] = $this;
     }
     return $saved;
 }