public function update(Request $request, $id)
 {
     $e = EntityType::findOrFail($id);
     $e->name = $request->input('name');
     $icon = $request->input('icon');
     $e->icon = substr($icon, strpos($icon, '-') + 1);
     $e->save();
     $ids = $request->input('attribute_id');
     $names = $request->input('attribute_name');
     $types = $request->input('attribute_type');
     $saved = array();
     for ($i = 0; $i < count($ids); $i++) {
         $aid = $ids[$i];
         if ($aid == '' || $ids == -1) {
             $a = new AttributeType();
         } else {
             $a = AttributeType::findOrFail($aid);
         }
         $a->name = $names[$i];
         $a->datatype = $types[$i];
         $a->entity_type = $e->id;
         $a->order = $i;
         $a->save();
         $saved[] = $a->id;
     }
     AttributeType::where('entity_type', '=', $e->id)->whereNotIn('id', $saved)->delete();
     return redirect(url('/config'));
 }
 public function attribute($type)
 {
     if (is_string($type)) {
         $name = $type;
     } else {
         $name = $type->slug;
     }
     return AttributeType::where('entity_type', '=', $this->id)->where('slug', '=', $name)->first();
 }