public function deleteModel(Model $model) { $tablename = $model->getTablename(); try { return $this->app['db']->delete($tablename)->where($model->ids())->execute() instanceof PDOStatement; } catch (PDOException $original) { $e = new AdapterException('An error occurred in the database adapter while deleting the ' . $model::modelName()); $e->setException($original); throw $e; } }
/** * Attaches a model to the relationship by creating * a pivot model. * * @param Model $model * * @return self */ public function attach(Model $model) { // create pivot relation $pivot = new Pivot(); $pivot->setTablename($this->tablename); // build the local side $ids = $this->localModel->ids(); foreach ($ids as $property => $id) { $pivot->{$this->localKey} = $id; } // build the foreign side $ids = $model->ids(); foreach ($ids as $property => $id) { $pivot->{$this->foreignKey} = $id; } $pivot->save(); $model->pivot = $pivot; return $this; }