• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Eloquent\Model类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model的典型用法代码示例。如果您正苦于以下问题:PHP Model类的具体用法?PHP Model怎么用?PHP Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: createQuestion

 public function createQuestion(Model $questionable, $data, Model $author)
 {
     $question = new static();
     $question->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $questionable->questions()->save($question);
     return $question;
 }
开发者ID:DraperStudio,项目名称:Laravel-Questionable,代码行数:7,代码来源:Question.php


示例2: deleteThe

 /**
  * Delete the given model entity.
  *
  * @param Model $model  Model to be deleted.
  * @param string $msg   Message for a successful delete.
  * @param string $title Title for a successful delete.
  *
  * @return array
  */
 protected function deleteThe(Model $model, $msg = 'messages.deleted', $title = 'messages.success')
 {
     if ($model->delete()) {
         return ['title' => trans("admin::{$title}"), 'msg' => trans("admin::{$msg}")];
     }
     return reportError();
 }
开发者ID:BlazOrazem,项目名称:laravel-basis,代码行数:16,代码来源:BaseController.php


示例3: save

 /**
  * Attach a model instance to the parent model.
  *
  * This adds the field_id value
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function save(Model $model)
 {
     if ($this->fieldId) {
         $model->setAttribute($this->fieldKey, $this->fieldId);
     }
     return parent::save($model);
 }
开发者ID:czim,项目名称:laravel-pxlcms,代码行数:15,代码来源:HasOne.php


示例4: __construct

 /**
  * Create a new morph to many relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $name
  * @param  string  $table
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $relationName
  * @param  bool  $inverse
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
 {
     $this->inverse = $inverse;
     $this->morphType = $name . '_type';
     $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
     parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
 }
开发者ID:manhvu1212,项目名称:videoplatform,代码行数:20,代码来源:MorphToMany.php


示例5: 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);
 }
开发者ID:artissant,项目名称:stock,代码行数:14,代码来源:UserRepository.php


示例6: createReview

 /**
  * @param Model $reviewable
  * @param $data
  * @param Model $author
  *
  * @return static
  */
 public function createReview(Model $reviewable, $data, Model $author)
 {
     $review = new static();
     $review->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $reviewable->reviews()->save($review);
     return $review;
 }
开发者ID:patrickcurl,项目名称:draperstudio_laravel-reviewable,代码行数:14,代码来源:Review.php


示例7: attachRelationship

 /**
  * Attaches a relationship to the model
  *
  * @param String $relationshipName Name of relationship in request
  * @param Model  $model            Model that has the relationships
  * @param mixed  $relationshipData Model(s) to associate
  *
  * @return Model
  */
 public function attachRelationship($relationshipName, Model $model, $relationshipData)
 {
     if ($relationshipName === 'next') {
         $model->pipeable()->associate($relationshipData);
     }
     return $model;
 }
开发者ID:continuous-deployment,项目名称:pipes,代码行数:16,代码来源:ActionTransformer.php


示例8: import

 /**
  * Import an Eloquent
  *
  * @param Model $model
  * @param array $relations
  * @param int $batchSize
  * @param callable $callback
  * @internal param $type
  */
 public function import(Model $model, $relations = [], $batchSize = 750, callable $callback = null)
 {
     $batch = 0;
     $asQueryLoggind = $model->getConnection()->logging();
     $model->getConnection()->disableQueryLog();
     while (true) {
         // Increase the batch number
         $batch += 1;
         // Load records from the database
         $records = $model->newInstance()->with($relations)->skip($batchSize * ($batch - 1))->take($batchSize)->get();
         // Break out of the loop if we are out of records
         if (count($records) == 0) {
             break;
         }
         // Call the callback function to provide feedback on the import process
         if ($callback) {
             $callback($batch);
         }
         // Transform each record before sending it to Elasticsearch
         $data = [];
         foreach ($records as $record) {
             $data[] = ['index' => ['_id' => $record->getEsId()]];
             $data[] = $record->transform(!empty($relations));
         }
         // Bulk import the data to Elasticsearch
         $this->bulk($data);
     }
     if ($asQueryLoggind) {
         $model->getConnection()->enableQueryLog();
     }
 }
开发者ID:menthol,项目名称:Flexible,代码行数:40,代码来源:Index.php


示例9: aggregate

 /**
  * Aggregates data handling to the subclasses.
  *
  * @param  array       $data  the handling internediate data.
  * @param  array|Model $value the handling Model instance.
  * @return array              the resulting intermediate Format instance.
  */
 protected function aggregate(array $data, Model $value)
 {
     $data[self::KEY_OF_TABLE_NAME] = $value->getTable();
     $data[self::KEY_OF_FOREIGN_KEY] = $value->getForeignKey();
     $data[self::KEY_OF_OTHER_KEY] = $value->getOtherKey();
     return $data;
 }
开发者ID:shingoOKAWA,项目名称:yacache-l5-php,代码行数:14,代码来源:PivotFormat.php


示例10: mergeValues

 /**
  * Merges EAV "values" into the entity model, for easy access and
  * manipulation.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return void
  */
 protected function mergeValues(Model $model, Collection $values)
 {
     foreach ($values as $value) {
         $attribute = $value->getRelation($value->getAttributeRelation());
         $model->setAttribute($attribute->getAttributeKey(), $value->getValueKey());
     }
 }
开发者ID:sohailaammarocs,项目名称:lfc,代码行数:15,代码来源:EavValues.php


示例11: storeVehicle

 /**
  * Store Detail vehicle
  *
  * @param Request      $request
  * @param Model|Header $header
  * @param bool         $coverage
  *
  * @return bool
  */
 public function storeVehicle($request, $header, $coverage = false)
 {
     $this->data = $request->all();
     try {
         if ($this->data['year'] === 'old') {
             $this->data['year'] = $this->data['year_old'];
         }
         $id = date('U');
         $detail = ['id' => $id, 'ad_vehicle_type_id' => $this->data['vehicle_type']['id'], 'ad_vehicle_make_id' => $this->data['vehicle_make']['id'], 'ad_vehicle_model_id' => $this->data['vehicle_model']['id'], 'ad_retailer_product_category_id' => $this->data['category']['id'], 'year' => $this->data['year'], 'license_plate' => $this->data['license_plate'], 'use' => $this->data['use'], 'mileage' => (bool) $this->data['mileage'], 'insured_value' => $this->data['insured_value']];
         if ($coverage) {
             $detail['color'] = $this->data['color'];
             $detail['engine'] = $this->data['engine'];
             $detail['chassis'] = $this->data['chassis'];
             $detail['tonnage_capacity'] = $this->data['tonnage_capacity'];
             $detail['seat_number'] = $this->data['seat_number'];
         }
         $header->details()->create($detail);
         if ($coverage && $this->getDetailById($id)) {
             return true;
         }
         return true;
     } catch (QueryException $e) {
         $this->errors = $e->getMessage();
     }
     return false;
 }
开发者ID:sibasbo,项目名称:sibas,代码行数:35,代码来源:DetailRepository.php


示例12: createRating

 /**
  * @param Model $ratingable
  * @param $data
  * @param Model $author
  *
  * @return static
  */
 public function createRating(Model $ratingable, $data, Model $author)
 {
     $rating = new static();
     $rating->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $ratingable->ratings()->save($rating);
     return $rating;
 }
开发者ID:autocar,项目名称:rating,代码行数:14,代码来源:Rating.php


示例13: attachTags

 /**
  * @param $model
  * @param $tagArray [Input::get('tag') ]
  * update the taggables
  */
 public function attachTags(Model $model, array $tagArray)
 {
     // attach related tags
     // fetch all tags
     $tags = $model->tags;
     // fetch all tags in the database assosiated with this event
     $attachedTags = $tags->lists('id');
     if (!empty($attachedTags)) {
         // if there are any tags assosiated with the event
         if (empty($tagArray)) {
             // if no tags in the GET REQUEST, delete all the tags
             foreach ($attachedTags as $tag) {
                 // delete all the tags
                 $model->tags()->detach($tag);
             }
         } else {
             // If the used tags is unselected in the GET REQUEST, delete the tags
             foreach ($attachedTags as $tag) {
                 if (!in_array($tag, $tagArray)) {
                     $model->tags()->detach($tag);
                 }
             }
         }
     }
     // attach the tags
     if (!empty($tagArray)) {
         $model->tags()->sync($tagArray, true);
     }
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:34,代码来源:TagRepository.php


示例14: authorizeForResults

 /**
  * @param Model $model
  * @param       $column
  * @return mixed
  */
 protected function authorizeForResults(Model $model, $column)
 {
     if (!array_key_exists($column, $model->toArray())) {
         return $this->authorize('add_activity', $model);
     }
     return $this->authorize('edit_activity', $model);
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:12,代码来源:AuthorizesByRequestType.php


示例15: destroy

 /**
  * 删除资源
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @return mixed
  * @throws \Exception
  */
 public function destroy(Model $model)
 {
     if ($model->delete()) {
         return $this->success('删除成功');
     }
     return $this->error('删除失败');
 }
开发者ID:netxinyi,项目名称:meigui,代码行数:15,代码来源:ResourceTrait.php


示例16: 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();
             }
         }
     }
 }
开发者ID:boyhagemann,项目名称:uploads,代码行数:34,代码来源:SaveFileToDisk.php


示例17: created

 public function created(Model $model)
 {
     if ($model->hashidStrategy() == 'id') {
         $model->generateHashidFromId();
         $model->save();
     }
 }
开发者ID:DraperStudio,项目名称:Laravel-Database,代码行数:7,代码来源:HashidObserver.php


示例18: __construct

 public function __construct(\Illuminate\Database\Eloquent\Model $extra)
 {
     $this->common = $extra->toArray();
     $this->composition = $extra->composition->toArray();
     $this->atmosphere = $extra->atmosphere->toArray();
     $this->orbit = $extra->orbit->toArray();
 }
开发者ID:Qeenslet,项目名称:elite-lara,代码行数:7,代码来源:planetExtraInfo.php


示例19: createAnswer

 /**
  * @param Model $question
  * @param       $data
  * @param Model $author
  *
  * @return static
  */
 public function createAnswer(Model $question, $data, Model $author)
 {
     $answer = new static();
     $answer->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $question->anwers()->save($answer);
     return $answer;
 }
开发者ID:tshafer,项目名称:laravel-questionable,代码行数:14,代码来源:Answer.php


示例20: createComment

 public function createComment(Model $commentable, $data, Model $creator)
 {
     $comment = new static();
     $comment->fill(array_merge($data, ['creator_id' => $creator->id, 'creator_type' => get_class($creator)]));
     $commentable->comments()->save($comment);
     return $comment;
 }
开发者ID:matheusgomes17,项目名称:Laravel-Commentable,代码行数:7,代码来源:Comment.php



注:本文中的Illuminate\Database\Eloquent\Model类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Relations\Relation类代码示例发布时间:2022-05-23
下一篇:
PHP Eloquent\Collection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap