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