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

headData()

Get the head data instance the fluent methods should write to.

schemaFactory()

Get the registered schema factory.

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.

description(string $description)

Set the page description.

themeColor(string $color, Media|string|null $media = null)

Set the theme color for the given media.

applicationName(string $name)

Set the application name.

colorScheme(string $scheme)

Set the supported color schemes.

referrer(string $policy)

Set the referrer policy.

viewport(string $content)

Set the viewport metadata.

appleWebAppTitle(string $title)

Set the Apple web app title.

webAppCapable(bool $capable = true)

Set whether the page supports web app mode.

appleWebAppStatusBarStyle(string $style)

Set the Apple web app status bar style.

canonical(string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)

Set the canonical URL and its normalization options.

robots(string|RobotsRule|array $directives)

Set the robots directives.

searchableByRobots()

Add a robots meta tag with the "all" directive, allowing search engines to index the page.

hiddenFromRobots()

Add a robots meta tag with the "none" directive, preventing search engines from indexing the page.

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.

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.

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.

ogAudio(string $url, string|null $type = null, string|null $secureUrl = null)

Add Open Graph audio.

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.

twitterImage(string $url, string|null $alt = null)

Set the Twitter card image.

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.

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.

prefetch(string $href, string|null $as = null)

Add a resource prefetch hint.

prefetchAsset(string $path, string|null $as = null)

Add an asset prefetch hint.

preconnect(string $href, bool|string|null $crossorigin = null)

Add a connection hint for an origin.

dnsPrefetch(string $href)

Add a DNS prefetch hint.

paginate(Paginator|CursorPaginator $paginator)

Add rel=prev/next links from a paginator instance.

alternates(array $alternates)

Add localized alternate URLs.

feed(string $href, string $title, string $type = 'rss')

Add a feed link.

schema(SchemaObject|array|callable $schema)

Add a JSON-LD schema object to the page.

meta(string $key, string $content, bool|null $property = null, Media|string|null $media = null)

Add a named or property-based meta tag.

link(string $rel, string $href, array $attributes = [])

Add a link with optional attributes.

icon(string $href, ImageType|string|null $type = null, string|null $sizes = null, Media|string|null $media = null)

Add an icon candidate.

favicon(string $href, ImageType|string|null $type = null, string|null $sizes = null, Media|string|null $media = null)

Add a favicon candidate.

appleTouchIcon(string $href, string|null $sizes = null)

Add an Apple touch icon.

maskIcon(string $href, string|null $color = null)

Add a pinned-tab mask icon.

manifest(string $href = '/site.webmanifest', bool|string|null $crossorigin = null)

Set the web app manifest link.

appleTouchStartupImage(string $href, Media|string|null $media = null)

Add an Apple startup image.

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.

static array
linkAttributes(array $attributes)

Remove unspecified link attributes.

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.

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.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Container $app, HeadRenderer $renderer, TagRegistry $registry)

Create the head manager.

inertiaGlobals(callable $callback)

Define head tags rendered as server-owned tags on every Inertia document.

defaults(callable $callback)

Define default head data merged beneath every page's head.

resolveDefaultsUsing(Closure|null $resolver)

Resolve default head data from the current request context.

errors(callable $callback)

Define head data for error pages.

resolveErrorsUsing(Closure|null $resolver)

Resolve error head data from the current request context and status.

resolveCanonicalOriginUsing(Closure|null $resolver)

Resolve the canonical origin from the current request context.

inertia(string $prop = self::INERTIA_PROP)

Customize the Inertia prop the head elements are shared under.

string
inertiaProp()

Get the shared Inertia prop name.

extend(string $builder)

Register a custom tag builder to render on every head.

status(int $status)

Set the response status used to resolve error page head data.

array
toArray(int|null $status = null)

Resolve the document metadata as an array.

array
toElements(int|null $status = null)

Render the document head elements.

array
toInertiaElements(int|null $status = null)

Render the page-managed Inertia head elements.

render(int|null $status = null)

Render the document head as HTML.

renderForView(int|null $status = null)

Render tags for a Blade view, adding Inertia ownership attributes when the current request is rendering an Inertia page.

string
toHtml(int|null $status = null)

Get the rendered document head HTML.

flush()

Flush runtime data for the current request scope.

define(callable $callback)

Run a definition callback against a fresh head builder and return its data.

resolve(int|null $status = null)

Resolve all configured head layers into the final data for rendering.

resolveDocument(int|null $status = null)

Resolve server-owned globals beneath the page metadata.

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.

state()

Get the current coroutine's head state.

Request|null
request()

Get the current request or the application's console request.

Route|null
route()

Get the current request's route.

Details

at line 346
protected HeadData headData()

Get the head data instance the fluent methods should write to.

Return Value

HeadData

at line 354
protected SchemaFactory schemaFactory()

Get the registered schema factory.

Return Value

SchemaFactory

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.

Parameters

string $title
string|null $prefix
string|null $suffix
bool|null $exact

Return Value

BuildsHead

in BuildsHead at line 57
BuildsHead description(string $description)

Set the page description.

Parameters

string $description

Return Value

BuildsHead

in BuildsHead at line 67
BuildsHead themeColor(string $color, Media|string|null $media = null)

Set the theme color for the given media.

Parameters

string $color
Media|string|null $media

Return Value

BuildsHead

in BuildsHead at line 75
BuildsHead applicationName(string $name)

Set the application name.

Parameters

string $name

Return Value

BuildsHead

in BuildsHead at line 83
BuildsHead colorScheme(string $scheme)

Set the supported color schemes.

Parameters

string $scheme

Return Value

BuildsHead

in BuildsHead at line 91
BuildsHead referrer(string $policy)

Set the referrer policy.

Parameters

string $policy

Return Value

BuildsHead

in BuildsHead at line 99
BuildsHead viewport(string $content)

Set the viewport metadata.

Parameters

string $content

Return Value

BuildsHead

in BuildsHead at line 107
BuildsHead appleWebAppTitle(string $title)

Set the Apple web app title.

Parameters

string $title

Return Value

BuildsHead

in BuildsHead at line 115
BuildsHead webAppCapable(bool $capable = true)

Set whether the page supports web app mode.

Parameters

bool $capable

Return Value

BuildsHead

in BuildsHead at line 123
BuildsHead appleWebAppStatusBarStyle(string $style)

Set the Apple web app status bar style.

Parameters

string $style

Return Value

BuildsHead

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.

Parameters

string|null $url
bool|null $forceHttps
bool|null $trailingSlash

Return Value

BuildsHead

in BuildsHead at line 143
BuildsHead robots(string|RobotsRule|array $directives)

Set the robots directives.

Parameters

string|RobotsRule|array $directives

Return Value

BuildsHead

in BuildsHead at line 153
BuildsHead searchableByRobots()

Add a robots meta tag with the "all" directive, allowing search engines to index the page.

Return Value

BuildsHead

in BuildsHead at line 161
BuildsHead hiddenFromRobots()

Add a robots meta tag with the "none" directive, preventing search engines from indexing the page.

Return Value

BuildsHead

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.

Parameters

OgType|string|null $type
string|null $title
string|null $description
string|null $url
string|null $image
string|null $video
string|null $audio
string|null $siteName
string|null $locale
string|null $determiner

Return Value

BuildsHead

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.

Parameters

string $url
string|null $alt
int|null $width
int|null $height
ImageType|string|null $type
string|null $secureUrl

Return Value

BuildsHead

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.

Parameters

string $url
string|null $alt
int|null $width
int|null $height
string|null $type
string|null $secureUrl

Return Value

BuildsHead

in BuildsHead at line 232
BuildsHead ogAudio(string $url, string|null $type = null, string|null $secureUrl = null)

Add Open Graph audio.

Parameters

string $url
string|null $type
string|null $secureUrl

Return Value

BuildsHead

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.

Parameters

TwitterCard|string|null $card
string|null $site
string|null $creator
string|null $title
string|null $description
string|null $image

Return Value

BuildsHead

in BuildsHead at line 265
BuildsHead twitterImage(string $url, string|null $alt = null)

Set the Twitter card image.

Parameters

string $url
string|null $alt

Return Value

BuildsHead

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.

Parameters

string $href
string|null $as
bool|string|null $crossorigin
ImageType|string|null $type
Media|string|null $media

Return Value

BuildsHead

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.

Parameters

string $path
string|null $as
bool|string|null $crossorigin
ImageType|string|null $type
Media|string|null $media

Return Value

BuildsHead

in BuildsHead at line 295
BuildsHead prefetch(string $href, string|null $as = null)

Add a resource prefetch hint.

Parameters

string $href
string|null $as

Return Value

BuildsHead

in BuildsHead at line 305
BuildsHead prefetchAsset(string $path, string|null $as = null)

Add an asset prefetch hint.

Parameters

string $path
string|null $as

Return Value

BuildsHead

in BuildsHead at line 315
BuildsHead preconnect(string $href, bool|string|null $crossorigin = null)

Add a connection hint for an origin.

Parameters

string $href
bool|string|null $crossorigin

Return Value

BuildsHead

in BuildsHead at line 325
BuildsHead dnsPrefetch(string $href)

Add a DNS prefetch hint.

Parameters

string $href

Return Value

BuildsHead

in BuildsHead at line 337
BuildsHead paginate(Paginator|CursorPaginator $paginator)

Add rel=prev/next links from a paginator instance.

Parameters

Paginator|CursorPaginator $paginator

Return Value

BuildsHead

in BuildsHead at line 349
BuildsHead alternates(array $alternates)

Add localized alternate URLs.

Parameters

array $alternates

Return Value

BuildsHead

in BuildsHead at line 359
BuildsHead feed(string $href, string $title, string $type = 'rss')

Add a feed link.

Parameters

string $href
string $title
string $type

Return Value

BuildsHead

in BuildsHead at line 371
BuildsHead schema(SchemaObject|array|callable $schema)

Add a JSON-LD schema object to the page.

Parameters

SchemaObject|array|callable $schema

Return Value

BuildsHead

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.

Parameters

string $key
string $content
bool|null $property
Media|string|null $media

Return Value

BuildsHead

Add a link with optional attributes.

Parameters

string $rel
string $href
array $attributes

Return Value

BuildsHead

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.

Parameters

string $href
ImageType|string|null $type
string|null $sizes
Media|string|null $media

Return Value

BuildsHead

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.

Parameters

string $href
ImageType|string|null $type
string|null $sizes
Media|string|null $media

Return Value

BuildsHead

in BuildsHead at line 427
BuildsHead appleTouchIcon(string $href, string|null $sizes = null)

Add an Apple touch icon.

Parameters

string $href
string|null $sizes

Return Value

BuildsHead

in BuildsHead at line 437
BuildsHead maskIcon(string $href, string|null $color = null)

Add a pinned-tab mask icon.

Parameters

string $href
string|null $color

Return Value

BuildsHead

in BuildsHead at line 447
BuildsHead manifest(string $href = '/site.webmanifest', bool|string|null $crossorigin = null)

Set the web app manifest link.

Parameters

string $href
bool|string|null $crossorigin

Return Value

BuildsHead

in BuildsHead at line 457
BuildsHead appleTouchStartupImage(string $href, Media|string|null $media = null)

Add an Apple startup image.

Parameters

string $href
Media|string|null $media

Return Value

BuildsHead

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.

Parameters

string $name
string $manifest
string|null $themeColor
string|null $appleTouchIcon
string|null $appleTouchIconSizes
string|null $appleWebAppStatusBarStyle

Return Value

BuildsHead

in BuildsHead at line 501
static protected array linkAttributes(array $attributes)

Remove unspecified link attributes.

Parameters

array $attributes

Return Value

array

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 83
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 54
__construct(Container $app, HeadRenderer $renderer, TagRegistry $registry)

Create the head manager.

Parameters

Container $app
HeadRenderer $renderer
TagRegistry $registry

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.

Parameters

callable $callback

Return Value

HeadManager

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.

Parameters

callable $callback

Return Value

HeadManager

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.

Parameters

Closure|null $resolver

Return Value

HeadManager

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.

Parameters

callable $callback

Return Value

HeadManager

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.

Parameters

Closure|null $resolver

Return Value

HeadManager

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.

Parameters

Closure|null $resolver

Return Value

HeadManager

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.

Parameters

string $prop

Return Value

HeadManager

at line 173
string inertiaProp()

Get the shared Inertia prop name.

Return Value

string

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.

Parameters

string $builder

Return Value

HeadManager

at line 196
HeadManager status(int $status)

Set the response status used to resolve error page head data.

Parameters

int $status

Return Value

HeadManager

at line 208
array toArray(int|null $status = null)

Resolve the document metadata as an array.

Parameters

int|null $status

Return Value

array

at line 218
array toElements(int|null $status = null)

Render the document head elements.

Parameters

int|null $status

Return Value

array

at line 228
array toInertiaElements(int|null $status = null)

Render the page-managed Inertia head elements.

Parameters

int|null $status

Return Value

array

at line 236
HtmlString render(int|null $status = null)

Render the document head as HTML.

Parameters

int|null $status

Return Value

HtmlString

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.

Parameters

int|null $status

Return Value

HtmlString

at line 261
string toHtml(int|null $status = null)

Get the rendered document head HTML.

Parameters

int|null $status

Return Value

string

at line 269
HeadManager flush()

Flush runtime data for the current request scope.

Return Value

HeadManager

at line 279
protected HeadData define(callable $callback)

Run a definition callback against a fresh head builder and return its data.

Parameters

callable $callback

Return Value

HeadData

at line 291
protected HeadData resolve(int|null $status = null)

Resolve all configured head layers into the final data for rendering.

Parameters

int|null $status

Return Value

HeadData

at line 325
protected HeadData resolveDocument(int|null $status = null)

Resolve server-owned globals beneath the page metadata.

Parameters

int|null $status

Return Value

HeadData

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.

Return Value

bool

at line 362
protected CurrentHead state()

Get the current coroutine's head state.

Return Value

CurrentHead

at line 370
protected Request|null request()

Get the current request or the application's console request.

Return Value

Request|null

at line 378
protected Route|null route()

Get the current request's route.

Return Value

Route|null