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