private function delete_category_if_exists()
 {
     $category = StoreCategory::where('display_name', 'test');
     if ($category != null) {
         $category->delete();
     }
 }
 public function ComposeWebPanelForms()
 {
     view()->composer('templates.' . \Config::get('webpanel.template') . 'webpanel.store.items._form', function ($view) {
         $view->with('categories', StoreCategory::lists('display_name', 'id'));
         $view->with('servers', StoreServer::lists('display_name', 'id'));
     });
     view()->composer('templates.' . \Config::get('webpanel.template') . 'webpanel.store.categories._form', function ($view) {
         $view->with('servers', StoreServer::lists('display_name', 'id'));
     });
     view()->composer('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.users._form', function ($view) {
         $view->with('roles', Role::lists('display_name', 'id'));
     });
     view()->composer('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.roles._form', function ($view) {
         $view->with('permissions', Permission::lists('display_name', 'id'));
     });
     view()->composer('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.permissions._form', function ($view) {
         $view->with('roles', Role::lists('display_name', 'id'));
     });
 }
 /**
  * Returns the Datatables data
  *
  * @return mixed
  */
 public function getData()
 {
     $categories = StoreCategory::select(['id', 'priority', 'display_name', 'require_plugin']);
     return Datatables::of($categories)->addColumn('action', function ($category) {
         $actions = view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.categories._actions', compact('category'))->render();
         return $actions;
     })->make();
 }
 private function get_category_id()
 {
     $category = StoreCategory::where('display_name', 'test-cat')->first();
     return $category->id;
 }
 public function PerformImport(Requests\ImportRequest $request)
 {
     $json_string = Storage::get('uploads/' . $request->input('fileName'));
     $json_object = json_decode($json_string);
     foreach ($json_object->categories as $category) {
         //Check if a category exists with the same name
         if (StoreCategory::where('require_plugin', $category->require_plugin)->count() > 0) {
             $ex_cats = StoreCategory::where('require_plugin', $category->require_plugin)->get();
             foreach ($ex_cats as $ex_cat) {
                 $ex_cat->delete();
             }
         }
     }
     //TODO: Handle Import Depending on JSON Versions
     //dd($json_object);
     foreach ($json_object->categories as $category) {
         //Delete the existing category
         // Save a new Category
         $cat = new StoreCategory((array) $category);
         $cat->save();
         //Save the Items
         foreach ($category->items as $item) {
             //Convert the attrs into the json sting
             $item->attrs = json_encode($item->attrs);
             $item->category_id = $cat->id;
             //Create the item
             $itm = new StoreItem((array) $item);
             $itm->save();
         }
     }
     Storage::delete('uploads/' . $request->input('fileName'));
     return redirect()->route('webpanel.store.tools.index');
 }