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