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