Skip to content

Functions ​

Hybridly exposes a few global and namespaced utility functions.

The functions live in the \Hybridly namespace and need to be imported before being used.

view ​

Renders a view with the given component and optional properties. The properties can be an array, an Arrayable or a data object.

See also: responses

php
use function Hybridly\view;

return view('user.show', $user);

properties ​

Returns updated properties for an existing view.

See also: properties-only responses

php
use function Hybridly\properties;

return properties([
	'user' => $user,
]);

dialog ​

Returns a dialog with the given properties and base view.

See also: dialogs

php
use function Hybridly\dialog;

return dialog(
	component: 'users.dit',
	properties: ['user' => $user],
	base: route('users.show', $user),
);

on_demand ​

Creates a partial-only property.

See also: partial-only properties

php
use function Hybridly\view;
use function Hybridly\on_demand;

return view('user.show', [
    'user' => $user,
  'posts' => on_demand(fn () => Post::forUser($user)->paginate()),
]);

merge ​

Creates a mergeable property.

When this property is included in a subsequent response, it is merged with the current frontend value instead of replacing it.

php
use function Hybridly\merge;
use function Hybridly\view;

return view('users.index', [
  'users' => merge(fn () => UserData::collection(User::latest()->limit(20)->get())),
]);

The merge semantics may be configured:

  • uniqueBy specifies a unique key to deduplicate items.
  • prepend specifies whether new items should be prepended instead of appended.
  • paths specifies the paths to merge instead of the root value.

deferred ​

Creates a partial property that will automatically be loaded in a subsequent partial reload when the page loads.

See also: deferred properties

php
use function Hybridly\view;
use function Hybridly\deferred;

return view('user.show', [
    'user' => $user,
    'posts' => deferred(fn () => Post::forUser($user)->paginate()),
]);

You may optionally provide a group name to defer properties together:

php
deferred(fn () => MetricsData::from($metrics), group: 'metrics')

to_external_url ​

Redirects to a non-hybrid view or an external domain.

See also: external redirects.

php
use function Hybridly\to_external_url;

return to_external_url('https://google.com');

is_hybrid ​

Determines whether the current request is hybrid. Optionally, a Illuminate\Http\Request instance can be given instead of using the current request.

php
use function Hybridly\is_hybrid;

if (is_hybrid()) {
  // ...
}

is_partial ​

Determines whether the current request is a partial reload. Optionally, a Illuminate\Http\Request instance can be given instead of using the current request.

php
use function Hybridly\is_partial;

if (is_partial()) {
  // ...
}

partial_headers ​

Generates headers for testing partial requests. The first parameter is the view component name, and the second and third parameters are an array of only and except properties, respectively.

See also: partial reloads

php
use function Hybridly\Testing\partial_headers;

get('/', partial_headers('users.show', only: ['posts']))
    ->assertMissingHybridProperty('user')
    ->assertHybridProperty('posts');

hybridly ​

This functions returns the Hybridly\Hybridly singleton instance. When possible, you should prefer dependency injection instead.