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