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