HeadManager
class HeadManager implements Arrayable, Htmlable
Traits
Constants
| INERTIA_PROP |
|
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected HeadData | $inertiaGlobals | ||
| protected HeadData | $defaults | ||
| protected string | $inertiaProp | ||
| protected ErrorPages | $errorPages | ||
| protected null|HeadBuilder): mixed | $defaultsResolver | ||
| protected null|HeadBuilder, int): mixed | $errorsResolver |
Methods
Get the registered schema factory.
Use $exact to render the title without inherited prefix or suffix.
Set the theme color for the given media.
Set whether the page supports web app mode.
Set the Apple web app status bar style.
Set the canonical URL and its normalization options.
Add a robots meta tag with the "all" directive, allowing search engines to index the page.
Add a robots meta tag with the "none" directive, preventing search engines from indexing the page.
Set Open Graph metadata.
Add an Open Graph image.
Add an Open Graph video.
Add Open Graph audio.
Set Twitter card metadata.
Set the Twitter card image.
Add a resource preload hint.
Add an asset preload hint.
Add a resource prefetch hint.
Add an asset prefetch hint.
Add a connection hint for an origin.
Add a named or property-based meta tag.
Add a link with optional attributes.
Add an icon candidate.
Add a favicon candidate.
Add an Apple touch icon.
Add a pinned-tab mask icon.
Set the web app manifest link.
Add an Apple startup image.
Set progressive web app metadata.
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Define head tags rendered as server-owned tags on every Inertia document.
Define default head data merged beneath every page's head.
Resolve default head data from the current request context.
Define head data for error pages.
Resolve error head data from the current request context and status.
Resolve the canonical origin from the current request context.
Customize the Inertia prop the head elements are shared under.
Get the shared Inertia prop name.
Register a custom tag builder to render on every head.
Set the response status used to resolve error page head data.
Resolve the document metadata as an array.
Render the document head elements.
Render the page-managed Inertia head elements.
Render the document head as HTML.
Render tags for a Blade view, adding Inertia ownership attributes when the current request is rendering an Inertia page.
Get the rendered document head HTML.
Flush runtime data for the current request scope.
Run a definition callback against a fresh head builder and return its data.
Resolve all configured head layers into the final data for rendering.
Resolve server-owned globals beneath the page metadata.
Determine if the current request is rendering an Inertia page. Inertia stores the page in coroutine-local state before the root view renders, so this holds at any depth of the view tree, unlike the view's variables.
Get the current coroutine's head state.
Details
at line 346
protected HeadData
headData()
Get the head data instance the fluent methods should write to.
at line 354
protected SchemaFactory
schemaFactory()
Get the registered schema factory.
in
BuildsHead at line 47
BuildsHead
title(string $title, string|null $prefix = null, string|null $suffix = null, bool|null $exact = null)
Use $exact to render the title without inherited prefix or suffix.
in
BuildsHead at line 57
BuildsHead
description(string $description)
Set the page description.
in
BuildsHead at line 67
BuildsHead
themeColor(string $color, Media|string|null $media = null)
Set the theme color for the given media.
in
BuildsHead at line 75
BuildsHead
applicationName(string $name)
Set the application name.
in
BuildsHead at line 83
BuildsHead
colorScheme(string $scheme)
Set the supported color schemes.
in
BuildsHead at line 91
BuildsHead
referrer(string $policy)
Set the referrer policy.
in
BuildsHead at line 99
BuildsHead
viewport(string $content)
Set the viewport metadata.
in
BuildsHead at line 107
BuildsHead
appleWebAppTitle(string $title)
Set the Apple web app title.
in
BuildsHead at line 115
BuildsHead
webAppCapable(bool $capable = true)
Set whether the page supports web app mode.
in
BuildsHead at line 123
BuildsHead
appleWebAppStatusBarStyle(string $style)
Set the Apple web app status bar style.
in
BuildsHead at line 131
BuildsHead
canonical(string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)
Set the canonical URL and its normalization options.
in
BuildsHead at line 143
BuildsHead
robots(string|RobotsRule|array $directives)
Set the robots directives.
in
BuildsHead at line 153
BuildsHead
searchableByRobots()
Add a robots meta tag with the "all" directive, allowing search engines to index the page.
in
BuildsHead at line 161
BuildsHead
hiddenFromRobots()
Add a robots meta tag with the "none" directive, preventing search engines from indexing the page.
in
BuildsHead at line 169
BuildsHead
og(OgType|string|null $type = null, string|null $title = null, string|null $description = null, string|null $url = null, string|null $image = null, string|null $video = null, string|null $audio = null, string|null $siteName = null, string|null $locale = null, string|null $determiner = null)
Set Open Graph metadata.
in
BuildsHead at line 200
BuildsHead
ogImage(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, ImageType|string|null $type = null, string|null $secureUrl = null)
Add an Open Graph image.
in
BuildsHead at line 216
BuildsHead
ogVideo(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, string|null $type = null, string|null $secureUrl = null)
Add an Open Graph video.
in
BuildsHead at line 232
BuildsHead
ogAudio(string $url, string|null $type = null, string|null $secureUrl = null)
Add Open Graph audio.
in
BuildsHead at line 242
BuildsHead
twitter(TwitterCard|string|null $card = null, string|null $site = null, string|null $creator = null, string|null $title = null, string|null $description = null, string|null $image = null)
Set Twitter card metadata.
in
BuildsHead at line 265
BuildsHead
twitterImage(string $url, string|null $alt = null)
Set the Twitter card image.
in
BuildsHead at line 275
BuildsHead
preload(string $href, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)
Add a resource preload hint.
in
BuildsHead at line 285
BuildsHead
preloadAsset(string $path, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)
Add an asset preload hint.
in
BuildsHead at line 295
BuildsHead
prefetch(string $href, string|null $as = null)
Add a resource prefetch hint.
in
BuildsHead at line 305
BuildsHead
prefetchAsset(string $path, string|null $as = null)
Add an asset prefetch hint.
in
BuildsHead at line 315
BuildsHead
preconnect(string $href, bool|string|null $crossorigin = null)
Add a connection hint for an origin.
in
BuildsHead at line 325
BuildsHead
dnsPrefetch(string $href)
Add a DNS prefetch hint.
in
BuildsHead at line 337
BuildsHead
paginate(Paginator|CursorPaginator $paginator)
Add rel=prev/next links from a paginator instance.
in
BuildsHead at line 349
BuildsHead
alternates(array $alternates)
Add localized alternate URLs.
in
BuildsHead at line 359
BuildsHead
feed(string $href, string $title, string $type = 'rss')
Add a feed link.
in
BuildsHead at line 371
BuildsHead
schema(SchemaObject|array|callable $schema)
Add a JSON-LD schema object to the page.
in
BuildsHead at line 385
BuildsHead
meta(string $key, string $content, bool|null $property = null, Media|string|null $media = null)
Add a named or property-based meta tag.
in
BuildsHead at line 397
BuildsHead
link(string $rel, string $href, array $attributes = [])
Add a link with optional attributes.
in
BuildsHead at line 407
BuildsHead
icon(string $href, ImageType|string|null $type = null, string|null $sizes = null, Media|string|null $media = null)
Add an icon candidate.
in
BuildsHead at line 419
BuildsHead
favicon(string $href, ImageType|string|null $type = null, string|null $sizes = null, Media|string|null $media = null)
Add a favicon candidate.
in
BuildsHead at line 427
BuildsHead
appleTouchIcon(string $href, string|null $sizes = null)
Add an Apple touch icon.
in
BuildsHead at line 437
BuildsHead
maskIcon(string $href, string|null $color = null)
Add a pinned-tab mask icon.
in
BuildsHead at line 447
BuildsHead
manifest(string $href = '/site.webmanifest', bool|string|null $crossorigin = null)
Set the web app manifest link.
in
BuildsHead at line 457
BuildsHead
appleTouchStartupImage(string $href, Media|string|null $media = null)
Add an Apple startup image.
in
BuildsHead at line 467
BuildsHead
pwa(string $name, string $manifest = '/site.webmanifest', string|null $themeColor = null, string|null $appleTouchIcon = null, string|null $appleTouchIconSizes = '180x180', string|null $appleWebAppStatusBarStyle = null)
Set progressive web app metadata.
in
BuildsHead at line 501
static protected array
linkAttributes(array $attributes)
Remove unspecified link attributes.
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 54
__construct(Container $app, HeadRenderer $renderer, TagRegistry $registry)
Create the head manager.
at line 74
HeadManager
inertiaGlobals(callable $callback)
Define head tags rendered as server-owned tags on every Inertia document.
On the shared manager, these tags apply to every request in the worker.
at line 89
HeadManager
defaults(callable $callback)
Define default head data merged beneath every page's head.
On the shared manager, these defaults apply to every request in the worker.
at line 104
HeadManager
resolveDefaultsUsing(Closure|null $resolver)
Resolve default head data from the current request context.
On the shared manager, the callback applies to every request in the worker.
at line 119
HeadManager
errors(callable $callback)
Define head data for error pages.
On the shared manager, these error definitions apply to every request in the worker.
at line 134
HeadManager
resolveErrorsUsing(Closure|null $resolver)
Resolve error head data from the current request context and status.
On the shared manager, the callback applies to every request in the worker.
at line 149
HeadManager
resolveCanonicalOriginUsing(Closure|null $resolver)
Resolve the canonical origin from the current request context.
The callback persists in a static property and affects every request in the worker.
at line 162
HeadManager
inertia(string $prop = self::INERTIA_PROP)
Customize the Inertia prop the head elements are shared under.
On the shared manager, the prop name applies to every request in the worker.
at line 173
string
inertiaProp()
Get the shared Inertia prop name.
at line 186
HeadManager
extend(string $builder)
Register a custom tag builder to render on every head.
When the registry is the application's worker-shared registry, the builder affects every request in the worker.
at line 196
HeadManager
status(int $status)
Set the response status used to resolve error page head data.
at line 208
array
toArray(int|null $status = null)
Resolve the document metadata as an array.
at line 218
array
toElements(int|null $status = null)
Render the document head elements.
at line 228
array
toInertiaElements(int|null $status = null)
Render the page-managed Inertia head elements.
at line 236
HtmlString
render(int|null $status = null)
Render the document head as HTML.
at line 245
HtmlString
renderForView(int|null $status = null)
Render tags for a Blade view, adding Inertia ownership attributes when the current request is rendering an Inertia page.
at line 261
string
toHtml(int|null $status = null)
Get the rendered document head HTML.
at line 269
HeadManager
flush()
Flush runtime data for the current request scope.
at line 279
protected HeadData
define(callable $callback)
Run a definition callback against a fresh head builder and return its data.
at line 291
protected HeadData
resolve(int|null $status = null)
Resolve all configured head layers into the final data for rendering.
at line 325
protected HeadData
resolveDocument(int|null $status = null)
Resolve server-owned globals beneath the page metadata.
at line 337
protected bool
renderingInertiaPage()
Determine if the current request is rendering an Inertia page. Inertia stores the page in coroutine-local state before the root view renders, so this holds at any depth of the view tree, unlike the view's variables.
at line 362
protected CurrentHead
state()
Get the current coroutine's head state.
at line 370
protected Request|null
request()
Get the current request or the application's console request.
at line 378
protected Route|null
route()
Get the current request's route.