/** * Set the site_id of the model. * * If a site is currently active then it is used, otherwise the default site is used. * * @param Model $model * * @return void */ public function creating(Model $model) { if ($model instanceof SingleSiteInterface) { $site = $this->router->getActiveSite() ?: $this->site->findDefault(); $model->{SingleSiteInterface::ATTR_SITE} = $site ? $site->getId() : null; } }
/** * @return void */ public function boot(Router $router) { $site = $router->getActiveSite(); $this->app->singleton(Repositories\Asset::class, function () { return new Repositories\Asset(new Models\Asset(), new Models\AssetVersion()); }); $this->app->singleton(Repositories\Page::class, function () use($site) { return new Repositories\Page(new Models\Page(), $site); }); $this->app->singleton(Repositories\PageVersion::class, function () { return new Repositories\PageVersion(new Models\PageVersion()); }); $this->app->singleton(Repositories\Person::class, function () use($site) { return new Repositories\Person(new Models\Person(), $site); }); $this->app->singleton(Repositories\Group::class, function () { return new Repositories\Group(); }); $this->app->singleton(Repositories\Tag::class, function () use($site) { return new Repositories\Tag(new Models\Tag(), $site); }); $this->app->singleton(Repositories\Template::class, function () { return new Repositories\Template(new Models\Template()); }); $this->app->singleton(Repositories\URL::class, function () use($site) { return new Repositories\URL(new Models\URL(), $site); }); }