repository = $history; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Islhd\Order\Repositories\Criteria\HistoryResourceCriteria::class); } /** * Display a list of history. * * @return Response */ public function index(HistoryRequest $request) { return $this->repository ->setPresenter(\Islhd\Order\Repositories\Presenter\HistoryPresenter::class) ->paginate(); } /** * Display history. * * @param Request $request * @param Model $history * * @return Response */ public function show(HistoryRequest $request, History $history) { return $history->setPresenter(\Islhd\Order\Repositories\Presenter\HistoryListPresenter::class); ; } /** * Create new history. * * @param Request $request * * @return Response */ public function store(HistoryRequest $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::history.name')]); $code = 204; $status = 'success'; $url = guard_url('order/history/' . $history->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/history'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the history. * * @param Request $request * @param Model $history * * @return Response */ public function update(HistoryRequest $request, History $history) { try { $data = $request->all(); $history->update($data); $message = trans('messages.success.updated', ['Module' => trans('order::history.name')]); $code = 204; $status = 'success'; $url = guard_url('order/history/' . $history->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/history/' . $history->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the history. * * @param Model $history * * @return Response */ public function destroy(HistoryRequest $request, History $history) { try { $history->delete(); $message = trans('messages.success.deleted', ['Module' => trans('order::history.name')]); $code = 202; $status = 'success'; $url = guard_url('order/history/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('order/history/' . $history->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); } }