/** * Edit a note */ function anyNote(Request $request) { $noteable = null; // deletion of note if ($request->has('do_delete')) { $note = Note::find($request->get('do_delete')); if ($note instanceof Note) { $back = self::back($note->noteable); $note->delete(); return redirect($back); } else { // TODO Find Better handling throw new \Exception('Invalid delete note call'); } } $edit = DataEdit::source(new Note()); // Create a new node for a noteable class if ($edit->status == 'create') { if ($request->has('noteable_id')) { $Noteable = self::model(); $noteable = $Noteable::find($request->get('noteable_id')); if ($noteable instanceof $Noteable) { $edit->model->noteable_id = $noteable->id; $edit->model->noteable_type = $Noteable; } else { throw new \Exception('Invalid create note call'); } } else { throw new \Exception('Invalid create note call'); } } else { $noteable = $edit->model->noteable; } // This is not working as expected in Rapyd, if necessay patch rapyd //$edit->back('insert|update',self::base($noteable).'/edit?show='.$noteable->id); //TODO $edit->add('note','Notiz', 'redactor') $edit->add('text', 'Notiz', 'textarea')->attributes(['class' => 'autofocus'])->rule('required|min:2'); $about = (string) $noteable; $edit->add('dummy', 'zu', 'text')->attributes(['readonly' => 'readonly'])->showValue($about)->updateValue($about)->insertValue($about); $edit->saved(function () use($noteable) { return redirect(self::base($noteable) . '/edit?show=' . $noteable->id); }); return $edit->view('edit', compact('edit')); }
<?php namespace App\Noteable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Culpa\BlameableObserver; use Culpa\CreatedBy; use Culpa\UpdatedBy; use Culpa\DeletedBy; class Note extends Model { use SoftDeletes; use CreatedBy; use UpdatedBy; use DeletedBy; protected $table = 'notes'; protected $fillable = ['text']; function noteable() { return $this->morphTo(); } } Note::observe(new BlameableObserver());