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