permissions = $permissions; } /** * Display the references to a given page. */ public function page(string $bookSlug, string $pageSlug) { /** @var Page $page */ $page = Page::visible()->whereSlugs($bookSlug, $pageSlug)->firstOrFail(); $baseQuery = $page->referencesTo() ->where('from_type', '=', (new Page())->getMorphClass()) ->with([ 'from' => fn(Relation $query) => $query->select(Page::$listAttributes), 'from.book' => fn(Relation $query) => $query->scopes('visible'), 'from.chapter' => fn(Relation $query) => $query->scopes('visible') ]); $references = $this->permissions->restrictEntityRelationQuery( $baseQuery, 'references', 'from_id', 'from_type' )->get(); return view('pages.references', [ 'page' => $page, 'references' => $references, ]); } }