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