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