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