repository = $order; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Inventory\Purchase\Repositories\Criteria\OrderResourceCriteria::class); } /** * Display a list of order. * * @return Response */ public function index(OrderRequest $request) { return $this->repository ->setPresenter(\Inventory\Purchase\Repositories\Presenter\OrderPresenter::class) ->paginate(); } /** * Display order. * * @param Request $request * @param Model $order * * @return Response */ public function show(OrderRequest $request, Order $order) { return $order->setPresenter(\Inventory\Purchase\Repositories\Presenter\OrderListPresenter::class); ; } /** * Create new order. * * @param Request $request * * @return Response */ public function store(OrderRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('purchase::order.name')]); $code = 204; $status = 'success'; $url = guard_url('purchase/order/' . $order->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('purchase/order'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the order. * * @param Request $request * @param Model $order * * @return Response */ public function update(OrderRequest $request, Order $order) { try { $data = $request->all(); $order->update($data); $message = trans('messages.success.updated', ['Module' => trans('purchase::order.name')]); $code = 204; $status = 'success'; $url = guard_url('purchase/order/' . $order->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('purchase/order/' . $order->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the order. * * @param Model $order * * @return Response */ public function destroy(OrderRequest $request, Order $order) { try { $order->delete(); $message = trans('messages.success.deleted', ['Module' => trans('purchase::order.name')]); $code = 202; $status = 'success'; $url = guard_url('purchase/order/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('purchase/order/' . $order->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }