Example #1
0
 /**
  * Get an array of paginated model results.
  *
  * @param  int        $per_page
  * @param  array      $columns
  * @return Paginator
  */
 public function paginate($per_page = null, $columns = array('*'))
 {
     $per_page = $per_page ?: $this->model->per_page();
     // First we'll grab the Paginator instance and get the results. Then we can
     // feed those raw database results into the hydrate method to get models
     // for the results, which we'll set on the paginator and return it.
     $paginator = $this->table->paginate($per_page, $columns);
     $paginator->results = $this->hydrate($this->model, $paginator->results);
     return $paginator;
 }
Example #2
0
 /**
  * Delete a model from the database.
  *
  * @param  int  $id
  * @return int
  */
 public function delete($id = null)
 {
     // If the delete method is being called on an existing model, we only want to delete
     // that model. If it is being called from an Eloquent query model, it is probably
     // the developer's intention to delete more than one model, so we will pass the
     // delete statement to the query instance.
     if (!$this->exists) {
         return $this->query->delete();
     }
     $table = static::table(get_class($this));
     return DB::connection(static::$connection)->table($table)->delete($this->id);
 }
Example #3
0
 /**
  * Delete a model from the database.
  *
  * @param  int  $id
  * @return int
  */
 public function delete($id = null)
 {
     // If the delete method is being called on an existing model, we only want to delete
     // that model. If it is being called from an Eloquent query model, it is probably
     // the developer's intention to delete more than one model, so we will pass the
     // delete statement to the query instance.
     if (!$this->exists) {
         return $this->query->delete();
     }
     $success = DB::connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id);
     if ($success) {
         \Events::launch(EVENT_ENTITY_DELETED, ['id' => $this->id, 'class' => get_class($this)]);
     }
     return $success;
 }
Example #4
0
 public function __call($method, $parameters)
 {
     $scope = 'scope_' . $method;
     if (method_exists($this->model, $scope)) {
         return $this->call_scope($scope, $parameters);
     }
     return parent::__call($method, $parameters);
 }