Hybridly
Hybridly\Hybridly
is a singleton instance that contains convenience methods for common actions. It can be accessed by dependency injection or by service location using the hybridly()
global function.
Note that most of the methods here are shortcuts to namespaced function.
view
Generates a HybridResponse
with the given component and optional properties. The properties can be an array, an Arrayable
or a data object.
See responses for more details.
Usage
return hybridly()->view('users.show', [
'user' => UserData::from($user)
]);
return hybridly()->view('users.show', [
'user' => UserData::from($user)
]);
properties
Generates a HybridResponse
with the given properties. The properties can be an array, an Arrayable
or a data object.
See responses for more details.
Usage
return hybridly()->properties([
'user' => UserData::from($user)
]);
return hybridly()->properties([
'user' => UserData::from($user)
]);
base
Makes the view a dialog and defines its base view. It takes a route name and its parameters as its arguments.
See dialogs for more details.
Usage
return hybridly()
->view('users.edit', [
'user' => UserData::from($user)
])
->base('users.show', $user);
return hybridly()
->view('users.edit', [
'user' => UserData::from($user)
])
->base('users.show', $user);
external
Generates a response for redirecting to an external website, or a non-hybrid view.
This can also be used to redirect to a hybrid view when it is not known whether the current request is hybrid or not.
See also:
to_external_url
See external redirects for more details.
Usage
return hybridly()->external('https://google.com');
return hybridly()->external('https://google.com');
partial
Creates a property that will only get evaluated and included when specifically requested through a partial reload.
See also:
partial
See partial reloads for more details.
Usage
return hybridly('booking.estimates.show', [
'booking' => BookingData::from($booking)
'estimates' => hybridly()->partial(function () {
return SearchEstimates::run($booking);
}),
]);
return hybridly('booking.estimates.show', [
'booking' => BookingData::from($booking)
'estimates' => hybridly()->partial(function () {
return SearchEstimates::run($booking);
}),
]);
deferred
Creates a partial property that will automatically be loaded in a subsequent partial reload when the page loads.
See deferred properties for more details.
Usage
return hybridly('booking.estimates.show', [
'booking' => BookingData::from($booking)
'estimates' => hybridly()->deferred(function () {
return SearchEstimates::run($booking);
}),
]);
return hybridly('booking.estimates.show', [
'booking' => BookingData::from($booking)
'estimates' => hybridly()->deferred(function () {
return SearchEstimates::run($booking);
}),
]);
isHybrid
See also:
is_hybrid
Determines whether the current request is hybrid. Optionally, a Illuminate\Http\Request
instance can be given instead of using the current request.
Usage
if (hybridly()->isHybrid()) {
// ...
}
if (hybridly()->isHybrid()) {
// ...
}
isPartial
See also:
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.
Usage
if (hybridly()->isPartial()) {
// ...
}
if (hybridly()->isPartial()) {
// ...
}
loadModuleFrom
See also: architecture
Loads views, layouts and components from the given directory. They must be located in the views
, layouts
and components
directories, respectively.
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModuleFrom(
directory: __DIR__,
namespace: 'billing'
);
}
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModuleFrom(
directory: __DIR__,
namespace: 'billing'
);
}
loadModulesFrom
See also: architecture
Loads views, layouts and components from the subdirectories of the given directory.
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModulesFrom(resource_path('modules'));
}
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModulesFrom(resource_path('modules'));
}
loadViewsFrom
See also: architecture
Recursively loads Vue files in the given directory and registers them as views for the given namespace (or no namespace if left empty).
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadViewsFrom(
directory: __DIR__.'/views',
namespace: 'billing',
);
}
public function boot(Hybridly $hybridly): void
{
$hybridly->loadViewsFrom(
directory: __DIR__.'/views',
namespace: 'billing',
);
}
loadLayoutsFrom
See also: architecture
Loads Vue files in the given directory and registers them as layouts for the given namespace (or no namespace if left empty).
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadLayoutsFrom(
directory: __DIR__.'/layouts',
namespace: 'billing',
);
}
public function boot(Hybridly $hybridly): void
{
$hybridly->loadLayoutsFrom(
directory: __DIR__.'/layouts',
namespace: 'billing',
);
}
loadComponentsFrom
See also: architecture
Loads Vue files in the given directory and registers them as components for the given namespace (or no namespace if left empty).
These components may be auto-imported by using their namespace and relative dot-notated path.
Usage
// src/Billing/BillingServiceProvider.php
public function boot(Hybridly $hybridly): void
{
$hybridly->loadComponentsFrom(
directory: __DIR__.'/components',
namespace: 'billing',
);
}
// src/Billing/BillingServiceProvider.php
public function boot(Hybridly $hybridly): void
{
$hybridly->loadComponentsFrom(
directory: __DIR__.'/components',
namespace: 'billing',
);
}
Using the example above, the component src/Billing/components/invoice/item.vue
can be auto-imported as <billing-invoice-item />
.