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