/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $order = new Order(); $order->setTotal($request->input('total')); $order->save(); foreach ($request->input('sweeties') as $sweetyId) { $order->sweeties()->attach(Sweety::findOrFail($sweetyId)); } $order->save(); return JsonResponse::create($order->load('sweeties')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Sweety::findOrFail($id)->delete(); }