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