repository = $order; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Order\Repositories\Criteria\OrderResourceCriteria::class); } /** * Display a list of order. * * @return Response */ public function index(OrderRequest $request) { return $this->repository ->setPresenter(\B2buy\Order\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(\B2buy\Order\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('order::order.name')]); $code = 204; $status = 'success'; $url = guard_url('order/order/' . $order->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/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('order::order.name')]); $code = 204; $status = 'success'; $url = guard_url('order/order/' . $order->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/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('order::order.name')]); $code = 202; $status = 'success'; $url = guard_url('order/order/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/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); } }