repository = $history; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Transaction\Repositories\Criteria\HistoryResourceCriteria::class); } /** * Display a list of history. * * @return Response */ public function index(HistoryRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Transaction\Repositories\Presenter\HistoryPresenter::class) ->$function(); } $histories = $this->repository->paginate(); return $this->response->title(trans('transaction::history.names')) ->view('transaction::history.index', true) ->data(compact('histories')) ->output(); } /** * Display history. * * @param Request $request * @param Model $history * * @return Response */ public function show(HistoryRequest $request, History $history) { if ($history->exists) { $view = 'transaction::history.show'; } else { $view = 'transaction::history.new'; } return $this->response->title(trans('app.view') . ' ' . trans('transaction::history.name')) ->data(compact('history')) ->view($view, true) ->output(); } /** * Show the form for creating a new history. * * @param Request $request * * @return Response */ public function create(HistoryRequest $request) { $history = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('transaction::history.name')) ->view('transaction::history.create', true) ->data(compact('history')) ->output(); } /** * Create new history. * * @param Request $request * * @return Response */ public function store(HistoryRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $history = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('transaction::history.name')])) ->code(204) ->status('success') ->url(guard_url('transaction/history/' . $history->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/transaction/history')) ->redirect(); } } /** * Show history for editing. * * @param Request $request * @param Model $history * * @return Response */ public function edit(HistoryRequest $request, History $history) { return $this->response->title(trans('app.edit') . ' ' . trans('transaction::history.name')) ->view('transaction::history.edit', true) ->data(compact('history')) ->output(); } /** * Update the history. * * @param Request $request * @param Model $history * * @return Response */ public function update(HistoryRequest $request, History $history) { try { $attributes = $request->all(); $history->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('transaction::history.name')])) ->code(204) ->status('success') ->url(guard_url('transaction/history/' . $history->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('transaction/history/' . $history->getRouteKey())) ->redirect(); } } /** * Remove the history. * * @param Model $history * * @return Response */ public function destroy(HistoryRequest $request, History $history) { try { $history->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('transaction::history.name')])) ->code(202) ->status('success') ->url(guard_url('transaction/history/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('transaction/history/' . $history->getRouteKey())) ->redirect(); } } /** * Remove multiple history. * * @param Model $history * * @return Response */ public function delete(HistoryRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('transaction::history.name')])) ->status("success") ->code(202) ->url(guard_url('transaction/history')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/transaction/history')) ->redirect(); } } /** * Restore deleted histories. * * @param Model $history * * @return Response */ public function restore(HistoryRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('transaction::history.name')])) ->status("success") ->code(202) ->url(guard_url('/transaction/history')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/transaction/history/')) ->redirect(); } } }