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