repository = $departments; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Company\Repositories\Criteria\DepartmentsResourceCriteria::class); } /** * Display a list of departments. * * @return Response */ public function index(DepartmentsRequest $request) { return $this->repository ->setPresenter(\Bixo\Company\Repositories\Presenter\DepartmentsPresenter::class) ->paginate(); } /** * Display departments. * * @param Request $request * @param Model $departments * * @return Response */ public function show(DepartmentsRequest $request, Departments $departments) { return $departments->setPresenter(\Bixo\Company\Repositories\Presenter\DepartmentsListPresenter::class); ; } /** * Create new departments. * * @param Request $request * * @return Response */ public function store(DepartmentsRequest $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('company::departments.name')]); $code = 204; $status = 'success'; $url = guard_url('company/departments/' . $departments->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/departments'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the departments. * * @param Request $request * @param Model $departments * * @return Response */ public function update(DepartmentsRequest $request, Departments $departments) { try { $data = $request->all(); $departments->update($data); $message = trans('messages.success.updated', ['Module' => trans('company::departments.name')]); $code = 204; $status = 'success'; $url = guard_url('company/departments/' . $departments->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/departments/' . $departments->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the departments. * * @param Model $departments * * @return Response */ public function destroy(DepartmentsRequest $request, Departments $departments) { try { $departments->delete(); $message = trans('messages.success.deleted', ['Module' => trans('company::departments.name')]); $code = 202; $status = 'success'; $url = guard_url('company/departments/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('company/departments/' . $departments->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); } }