本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::update方法的具体用法?PHP Model::update怎么用?PHP Model::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update a user.
*
* @param Model $item
* @param array $data
* @return bool|int
*/
public function update(Model $item, array $data)
{
if (isset($data['password'])) {
$data['password'] = bcrypt($data['password']);
}
return $item->update($data);
}
示例2: update
/**
* Update an existing model.
* @param array $input
* @throws Exception
* @return mixed
*/
public function update(array $input = [])
{
$this->beforeUpdate($input);
$return = parent::update($input);
$this->afterUpdate($input, $return);
return $return;
}
示例3: update
/**
* Update the model in the database.
*
* @param array $attributes
* @return bool|int
*/
public function update(array $attributes = [])
{
if (isset($attributes['alias']) && empty($attributes['alias'])) {
$name = $this->name;
if (isset($attributes['name'])) {
$name = $attributes['name'];
}
$attributes['alias'] = Str::slug($name) . '-' . Uuid::generate(4);
}
if (isset($attributes['galleries'])) {
if (empty($attributes['galleries'])) {
$attributes['galleries'] = [];
}
$attributes['galleries'] = json_encode($attributes['galleries']);
}
if (isset($attributes['attributes'])) {
if (empty($attributes['attributes'])) {
$attributes['attributes'] = [];
}
$attributes['attributes'] = json_encode($attributes['attributes']);
}
if (!parent::update($attributes)) {
throw new Exception('Cannot update product.');
}
return $this;
}
示例4: inlineUpdate
public function inlineUpdate($id)
{
$this->instance = $this->find($id);
if (empty($this->instance)) {
return false;
}
$data = $this->request->all();
$updated = false;
if (method_exists($this->instance, 'getRepository')) {
$repository = $this->instance->getRepository();
if (method_exists($repository, 'inlineSave')) {
if ($repository->inlineSave($data)) {
$updated = true;
} else {
return false;
}
}
}
if ($updated == false) {
$fillableFields = $this->instance->getFillable();
foreach ($data as $key => $value) {
if (in_array($key, $fillableFields)) {
$this->instance->{$key} = $value;
}
}
if ($this->instance->update()) {
$updated = true;
}
}
return $updated;
}
示例5: update
public function update(array $attributes = array(), array $options = array())
{
if (array_key_exists('file', $attributes)) {
$this->deleteFile();
$this->uploadFile($attributes['file'], $attributes['file_name']);
}
parent::update($attributes, $options);
}
示例6: updateModel
/**
* @param Model $model
* @param array $data
*
* @throws RepositoryException
*
* @return Model
*/
public function updateModel(Model $model, array $data)
{
if (!$model->update($data)) {
throw new RepositoryException('Could not be saved');
}
$this->makeModel();
return $model;
}
示例7: update
/**
* @param Model $model
* @param array $input
* @return bool
*/
public function update(Model $model, array $input)
{
$updated = $model->update($input);
if ($updated) {
app('cache')->flush();
}
return $updated;
}
示例8: update
/**
* Update permissions and roles of a route.
*
* @param array $attributes
* @return bool|int
*/
public function update(array $attributes = [])
{
if (!parent::update($attributes)) {
throw new Exception('Cannot update category.');
// @codeCoverageIgnore
}
return $this->fresh();
}
示例9: update
/**
* 执行更新操作
*
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return mixed
*/
public function update(Model $model)
{
$this->validateUpdate();
$form = $this->request()->all();
if ($model->update($form)) {
return $this->success('保存成功', $model);
}
return $this->error('修改失败,请稍后再试');
}
示例10: update
/**
* If a future month is being set to 0, set the value to null instead of 0
*/
public function update(array $attributes = [], array $options = [])
{
if (array_key_exists('hours_used', $attributes) && $attributes['hours_used'] == 0) {
if ($this->getStartDate() > \Carbon\Carbon::now()) {
$attributes['hours_used'] = null;
}
}
parent::update($attributes);
}
示例11: update
/**
* Update the model in the database.
*
* @param array $attributes
* @param array $options
* @return bool|int
*/
public function update(array $attributes = [], array $options = [])
{
if (Guardian::hasClients()) {
$attributes[Guardian::getClientColumn()] = Guardian::getClientId();
}
if ($this->locked) {
return false;
}
return parent::update($attributes, $options);
}
示例12: update
/**
* Update the model in the database.
*
* @param array $attributes
* @return bool|int
*/
public function update(array $attributes = [])
{
if (!empty($attributes['galleries'])) {
$attributes['galleries'] = json_encode($attributes['galleries']);
}
if (!parent::update($attributes)) {
throw new Exception('Cannot update product.');
}
return $this;
}
示例13: update
public function update(array $data = [])
{
unset($data['_method'], $data['_token']);
if (parent::update($data)) {
unset($data['color']);
if (Element::where('element_data_id', $this->id)->update($data)) {
return true;
}
}
return false;
}
示例14: update
public function update(array $attributes = [])
{
parent::update($attributes);
$instances = collect();
foreach ($attributes['instances'] as $instance) {
$instance['date'] = $attributes['date'];
$instances->push($this->instances()->updateOrCreate(array_merge(['id' => 0], array_only($instance, ['id'])), $instance));
}
$this->instances()->whereNotIn('id', $instances->pluck('id')->all())->delete();
return $this->setRelation('instances', $instances);
}
示例15: update
/**
* Update author with new data
*
* @param arrray $data
* @return null
*/
public function update(array $data = [])
{
$validator = $this->getValidator($data);
if (!$validator->validate()) {
$messages = [];
foreach ($validator->errors() as $fieldName => $errors) {
$messages[] = current($errors);
}
$message = implode("\n", $messages);
throw new \Exception($message);
}
return parent::update($data);
}