本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::save方法的具体用法?PHP Model::save怎么用?PHP Model::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* @param array $data
* @return bool
*/
public function insert(array $data = [])
{
$this->source->fill($data);
if ($this->source->save()) {
return $this->source->getKey();
}
return false;
}
示例2: delete
/**
* 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;
}
示例3: updated
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`, ',')")]);
}
}
}
示例4: update
/**
* 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);
}
示例5: save
public function save(array $options = array())
{
if (!isset($this->id)) {
$this->ordem = Tarefa::orderBy('ordem', 'DESC')->first()->ordem + 1;
}
return parent::save($options);
}
示例6: save
public function save(array $options = array())
{
$filename = $this->createBill($this->course()->getResults());
$this->amount = $this->course()->getResults()->participantNum;
$this->filename = $filename;
parent::save($options);
}
示例7: save
/**
* 存储操作
*
* 存储时尝试先存储 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;
}
}
示例8: createMainModel
/**
* 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();
}
示例9: save
/**
* 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);
}
示例10: refresh
/**
* 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;
}
示例11: onCrudSaved
/**
* 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();
}
}
}
}
示例12: save
public function save(array $options = [])
{
if (!$this->exists) {
$this->uid = $this->genNewUID();
}
return parent::save($options);
}
示例13: save
/**
* 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);
}
示例14: save
public function save(array $options = [])
{
if (!$this->exists && !$this->isDirty(static::CREATED_AT)) {
$this->setCreatedAt($this->freshTimestamp());
}
return parent::save($options);
}
示例15: save
public function save(array $options = [])
{
if ($this->relation) {
$this->relation->save();
}
parent::save($options);
}