php Illuminate-Database-Eloquent-Model类(方法)实例源码

下面列出了php Illuminate-Database-Eloquent-Model 类(方法)源码代码实例,从而了解它的用法。

作者:DraperStudi    项目:Laravel-Questionabl   
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;
 }

作者:BlazOraze    项目:laravel-basi   
/**
  * 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();
 }

作者:czi    项目:laravel-pxlcm   
/**
  * 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);
 }

作者:manhvu121    项目:videoplatfor   
/**
  * 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);
 }

作者:artissan    项目:stoc   
/**
  * 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);
 }

作者:patrickcur    项目:draperstudio_laravel-reviewabl   
/**
  * @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;
 }

作者:continuous-deploymen    项目:pipe   
/**
  * 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;
 }

作者:mentho    项目:Flexibl   
/**
  * 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();
     }
 }

作者:shingoOKAW    项目:yacache-l5-ph   
/**
  * 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;
 }

作者:sohailaammaroc    项目:lf   
/**
  * 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());
     }
 }

作者:sibasb    项目:siba   
/**
  * 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;
 }

作者:autoca    项目:ratin   
/**
  * @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;
 }

作者:christiannwamb    项目:laravel-sit   
/**
  * @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);
     }
 }

作者:younginnovation    项目:aidstrea   
/**
  * @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);
 }

作者:netxiny    项目:meigu   
/**
  * 删除资源
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @return mixed
  * @throws \Exception
  */
 public function destroy(Model $model)
 {
     if ($model->delete()) {
         return $this->success('删除成功');
     }
     return $this->error('删除失败');
 }

作者:boyhageman    项目:upload   
/**
  * 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();
             }
         }
     }
 }

作者:DraperStudi    项目:Laravel-Databas   
public function created(Model $model)
 {
     if ($model->hashidStrategy() == 'id') {
         $model->generateHashidFromId();
         $model->save();
     }
 }

作者:Qeensle    项目:elite-lar   
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();
 }

作者:tshafe    项目:laravel-questionabl   
/**
  * @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;
 }

作者:matheusgomes1    项目:Laravel-Commentabl   
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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号