Ejemplo n.º 1
0
 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');
 }