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