Example #1
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 #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();
     }
     $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;
 }