private function create_category() { $category = StoreCategory::where('display_name', 'test-cat')->first(); if ($category != null) { $category->delete(); } $category = new StoreCategory(); $category->priority = 5; $category->display_name = "test-cat"; $category->description = "Cat for Itm Test"; $category->require_plugin = "integration_test"; $category->web_description = "Test Category for Item Test"; $category->web_color = "#000000"; $category->enable_server_restriction = 0; $category->save(); }
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'); }