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) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Kscc\Organization\Repositories\Presenter\OrganizationPresenter::class) ->$function(); } $organizations = $this->repository->paginate(); return $this->response->setMetaTitle(trans('organization::organization.names')) ->view('organization::organization.index', true) ->data(compact('organizations', 'view')) ->output(); } /** * Display organization. * * @param Request $request * @param Model $organization * * @return Response */ public function show(OrganizationRequest $request, Organization $organization) { if ($organization->exists) { $view = 'organization::organization.show'; } else { $view = 'organization::organization.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('organization::organization.name')) ->data(compact('organization')) ->view($view, true) ->output(); } /** * Show the form for creating a new organization. * * @param Request $request * * @return Response */ public function create(OrganizationRequest $request) { $organization = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('organization::organization.name')) ->view('organization::organization.create', true) ->data(compact('organization')) ->output(); } /** * Create new organization. * * @param Request $request * * @return Response */ public function store(OrganizationRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $organization = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('organization::organization.name')])) ->code(204) ->status('success') ->url(guard_url('organization/organization/' . $organization->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/organization/organization')) ->redirect(); } } /** * Show organization for editing. * * @param Request $request * @param Model $organization * * @return Response */ public function edit(OrganizationRequest $request, Organization $organization) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('organization::organization.name')) ->view('organization::organization.edit', true) ->data(compact('organization')) ->output(); } /** * Update the organization. * * @param Request $request * @param Model $organization * * @return Response */ public function update(OrganizationRequest $request, Organization $organization) { try { $attributes = $request->all(); $organization->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('organization::organization.name')])) ->code(204) ->status('success') ->url(guard_url('organization/organization/' . $organization->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('organization/organization/' . $organization->getRouteKey())) ->redirect(); } } /** * Remove the organization. * * @param Model $organization * * @return Response */ public function destroy(OrganizationRequest $request, Organization $organization) { try { $organization->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('organization::organization.name')])) ->code(202) ->status('success') ->url(guard_url('organization/organization/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('organization/organization/' . $organization->getRouteKey())) ->redirect(); } } /** * Remove multiple organization. * * @param Model $organization * * @return Response */ public function delete(OrganizationRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('organization::organization.name')])) ->status("success") ->code(202) ->url(guard_url('organization/organization')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/organization/organization')) ->redirect(); } } /** * Restore deleted organizations. * * @param Model $organization * * @return Response */ public function restore(OrganizationRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('organization::organization.name')])) ->status("success") ->code(202) ->url(guard_url('/organization/organization')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/organization/organization/')) ->redirect(); } } }