/** * Listen to the Page saved event. * * @param \Soda\Cms\Models\Page $page */ public function created(Page $page) { if ($page->page_type_id !== null) { //if(!$page->type) $page->load('type'); ModelBuilder::fromTable('soda_' . $page->type->identifier)->forceFill(['page_id' => $page->id])->save(); } }
/** * Listen to the Block saved event. * * @param \Soda\Cms\Models\Block $block */ public function saved(Block $block) { if ($block->isDirty('is_shared')) { if (!$block->type) { $block->load('type'); } ModelBuilder::fromTable('soda_' . $block->type->identifier)->where($block->getRelatedField(), $block->id)->update(['is_shared' => $block->is_shared]); } }
public function modelQuery($page_id = null) { if (!$this->type) { $this->load('type'); } return ModelBuilder::fromTable('soda_' . $this->type->identifier)->where($this->getRelatedField(), $this->id)->where(function ($q) use($page_id) { $q->where('is_shared', 1); if ($page_id) { $q->orWhere('page_id', $page_id); } }); }
/** * Load a dynamic model * * @param $table * @param bool $autoprefix * * @return mixed */ public function model($table, $autoprefix = true) { if ($autoprefix) { $table = 'soda_' . $table; } return ModelBuilder::fromTable($table, []); }
protected function loadPageAttributes() { if (!$this->type) { $this->load('type'); } if (!$this->type) { $model = new ModelBuilder(); } else { $model = ModelBuilder::fromTable('soda_' . $this->type->identifier)->where($this->getRelatedField(), $this->id)->first(); if (!$model) { $model = ModelBuilder::fromTable('soda_' . $this->type->identifier)->newInstance(); } } return $this->setPageAttributes($model); }