entity->default_template_id); if (!$changing) { return; } if ($templateId === 0) { $this->entity->default_template_id = null; return; } $pageQueries = app()->make(PageQueries::class); $templateExists = $pageQueries->visibleTemplates() ->where('id', '=', $templateId) ->exists(); $this->entity->default_template_id = $templateExists ? $templateId : null; } /** * Get the default template for this entity (if visible). */ public function get(): Page|null { if (!$this->entity->default_template_id) { return null; } $pageQueries = app()->make(PageQueries::class); $page = $pageQueries->visibleTemplates(true) ->where('id', '=', $this->entity->default_template_id) ->first(); if ($page instanceof Page) { return $page; } return null; } }