- /**
- * Update the default page template used for this book.
- * Checks that, if changing, the provided value is a valid template and the user
- * has visibility of the provided page template id.
- */
- protected function updateBookDefaultTemplate(Book $book, int $templateId): void
- {
- $changing = $templateId !== intval($book->default_template_id);
- if (!$changing) {
- return;
- }
-
- if ($templateId === 0) {
- $book->default_template_id = null;
- $book->save();
- return;
- }
-
- $templateExists = Page::query()->visible()
- ->where('template', '=', true)
- ->where('id', '=', $templateId)
- ->exists();
-
- $book->default_template_id = $templateExists ? $templateId : null;
- $book->save();
- }
-