public function postBatch() { $file = Input::file('excel_file'); $result = Excel::load($file, function ($reader) { $reader->take(500); })->toArray(); $data = array_filter($result); if (isset($data[0][0]['vendor_id'])) { $data = $data[0]; } $i = 0; foreach ($data as $key => $value) { $cakes = new Cakes(); $cakes->vendor_id = $value['vendor_id']; $cakes->product_code = $value['product_code']; $cakes->title = $value['title']; $cakes->description = $value['description']; $cakes->type = $value['type']; $cakes->price = $value['price']; $cakes->availability = $value['availability']; $cakes->image = $value['image']; $cakes->city = $value['city']; if ($cakes->save()) { } else { $i++; } } if ($i) { return Redirect::to('/cake/index')->with('message', 'Error in cakes upload.'); } else { return Redirect::to('/cake/index')->with('message', 'Cakes upload succesfull.'); } }
$cakes->save(); return new JsonResponse($cake); }); //show a cake $app->get("/cakes/{id}", function ($id) { $cakes = new Cakes(); return new JsonResponse($cakes->getCake($id)); }); $app->patch("/cakes/{id}/update", function (Request $request, $id) { $cakes = new Cakes(); $oldCake = $cakes->getCake($id); if (!$oldCake) { return new Response("No cake by id {$id}", 404); } $newCake = json_decode($request->getContent(), true); // var_dump($newCake, $oldCake);die; $cake = array_merge($oldCake, $newCake); $cakes->updateCake($id, $cake); $cakes->save(); return new JsonResponse($cake); }); $app->delete("/cakes/{id}/delete", function ($id) { $cakes = new Cakes(); if (!$cakes->getCake($id)) { return new Response("No cake by id {$id}"); } $cakes->deleteCake($id); $cakes->save(); return new Response(); }); $app->run();