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) { return $this->repository ->setPresenter(\Btravel\Staff\Repositories\Presenter\StaffPresenter::class) ->paginate(); } /** * Display staff. * * @param Request $request * @param Model $staff * * @return Response */ public function show(StaffRequest $request, Staff $staff) { return $staff->setPresenter(\Btravel\Staff\Repositories\Presenter\StaffListPresenter::class); ; } /** * Create new staff. * * @param Request $request * * @return Response */ public function store(StaffRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('staff::staff.name')]); $code = 204; $status = 'success'; $url = guard_url('staff/staff/' . $staff->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('staff/staff'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the staff. * * @param Request $request * @param Model $staff * * @return Response */ public function update(StaffRequest $request, Staff $staff) { try { $data = $request->all(); $staff->update($data); $message = trans('messages.success.updated', ['Module' => trans('staff::staff.name')]); $code = 204; $status = 'success'; $url = guard_url('staff/staff/' . $staff->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('staff/staff/' . $staff->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the staff. * * @param Model $staff * * @return Response */ public function destroy(StaffRequest $request, Staff $staff) { try { $staff->delete(); $message = trans('messages.success.deleted', ['Module' => trans('staff::staff.name')]); $code = 202; $status = 'success'; $url = guard_url('staff/staff/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('staff/staff/' . $staff->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }