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