public function handle($command)
 {
     $model = FieldModel::find($command->id);
     $modelArray = $model->toArray();
     $model->delete();
     event(new FieldWasDeleted($modelArray));
 }
 /**
  * Handle the creation of the Field in the Database
  * @param $command
  * @return static
  */
 public function handle($command)
 {
     $command->namespace = EntityModel::find($command->entity_id)->namespace;
     $field = FieldModel::create((array) $command);
     event(new FieldWasCreated($field));
     return $field;
 }
 /**
  * @param object $command
  * @param callable $next
  *
  * @return mixed
  */
 public function execute($command, callable $next)
 {
     $model = FieldModel::find($command->id);
     if (!isset($command->locked)) {
         $command->locked = $model->locked;
     }
     return $next($command);
 }
 /**
  * Set the order for the field
  * @param $command
  */
 protected function setOrder($command)
 {
     $command->order = 1;
     $lastField = FieldModel::where('entity_id', $command->entity_id)->orderBy('order', 'DESC')->first();
     if (!is_null($lastField)) {
         $command->order = $lastField->order + 1;
     }
     return $command;
 }
 /**
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $order = 1;
     foreach ($command->fields as $field) {
         $f = FieldModel::find($field);
         $f->order = $order;
         $f->save();
         $order++;
     }
     return $field;
 }
 /**
  * Handle the creation of the Field in the Database
  * @param $command
  * @return static
  */
 public function handle($command)
 {
     $fields = (array) $command;
     $model = FieldModel::find($command->id);
     $rename = false;
     $oldSlug = $model->slug;
     if ($model->slug !== $command->slug) {
         $rename = true;
     }
     unset($fields['id']);
     $model->fill($fields);
     $model->save();
     event(new FieldWasEdited($model, $rename, $oldSlug));
     return $model;
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     return $this->responseWithItem($this->model->findOrFail($id), new FieldTransformer());
 }
 /**
  * @param object $command
  * @param callable $next
  *
  * @return mixed
  */
 public function execute($command, callable $next)
 {
     $field = FieldModel::find($command->id);
     $command->type = $field->type;
     return $next($command);
 }