protected function bootObservers() { Block::observe(BlockObserver::class); Page::observe(PageObserver::class); BlockType::observe(DynamicObserver::class); PageType::observe(DynamicObserver::class); }
/** * Loads a page by it's slug * * @param $slug * * @return \Soda\Cms\Components\Pages\PageBuilder|void */ public function loadPageBySlug($slug) { $page = Page::with('type', 'blocks')->where('slug', '/' . ltrim($slug, '/'))->first(); if ($page) { return $this->loadPage($page); } return $this->handleNotFound(); }
public function __construct(ModelBuilder $modelBuilder) { $type = Route::current()->getParameter('type'); $page_id = Route::current()->getParameter('page_id'); $this->page = $page_id ? Page::find($page_id) : new Page(); $block = $page_id ? $this->page->blocks() : new Block(); $this->block = $block->with('type', 'type.fields')->where('identifier', $type)->first(); $this->model = Soda::dynamicModel('soda_' . $this->block->type->identifier, $this->block->type->fields->lists('field_name')->toArray()); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * * @return mixed */ public function handle($request, Closure $next, $guard = null) { config()->set('auth.defaults.guard', 'soda'); //this is a work around for a laravel bug - the guard flicks back to the default when run through an auth Gate //so we need to temporarily set the guard to the incomming guard here instead. Block::disableDrafts(); BlockType::disableDrafts(); Page::disableDrafts(); PageType::disableDrafts(); return $next($request); }
/** * Show the page. * * @return Response */ public function getIndex(Request $request) { if ($request->input('id')) { $page = $this->model->find($request->input('id')); } else { $page = $this->model->getRoots()->first(); //todo: from application. if (!$page) { $page = Page::createRoot(); } } $page_types = PageType::get(); $pages = $page ? $page->collectDescendants()->orderBy('position')->get()->toTree() : []; $tree = $this->htmlTree($pages, $this->hint); return view('soda::page.index', ['hint' => $this->hint, 'pages' => $pages, 'tree' => $tree, 'page_types' => $page_types]); }