public function save(\Illuminate\Http\Request $request, $id = false) { $this->setUpModel($request); $model = $id ? $this->model->find($id) : $this->model; $model->setUser($this->user); if ($model->id && !$model->canEdit()) { throw new \Exception('Editing denied.'); } if (!$model->id && !$model->canCreate()) { throw new \Exception('Creating denied.'); } foreach ($this->model->getColumns() as $column) { $colName = $column->getName(); if (Input::get($colName)) { $model->{$colName} = Input::get($colName); } } if (!$model->save()) { foreach ($model->getErrors() as $err) { $this->alert('warning', $err); } } $this->alert('success', "Data saved successfully.", true); return redirect($this->model->getSlug() . '/' . $model->id); }
public function saved(\Ormic\Model\Base $model) { // Don't try to create a datalog for the datalog model! if ($model->getTable() == 'datalog') { return true; } foreach ($model->getDirty() as $field => $new_value) { // Save the datalog entry. $datalog = new \Ormic\Model\Datalog(); $datalog->table = $model->getTable(); $datalog->date_and_time = date('Y-m-d H:i:s'); $datalog->row = $model->id; $datalog->field = $field; $datalog->old_value = $model->getOriginal($field); $datalog->new_value = $model->getAttributeTitle($field); //$new_value; $datalog->user_id = $model->getUser()->id; $datalog->save(); // Save additional entries if this field is the title. // foreach ($model->get) { // // } } return true; }