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)
]);
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)
]);
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);
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');
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);
}),
]);
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);
}),
]);
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()) {
// ...
}
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()) {
// ...
}
loadModule
See also: architecture
Loads views, layouts and components from the current directory.
The layouts and components must be located in the layouts
and components
directories, respectively. Views are loaded deeply by default.
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModule(namespace: 'billing');
}
You may set the deep
argument to false
to only load views in the views
directory instead of all the views in the current directory.
$hybridly->loadModule(namespace: 'billing', deep: false);
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'
);
}
You may specify which components of a module will be loaded by setting false
to the corresponding arguments:
public function boot(Hybridly $hybridly): void
{
$hybridly->loadModuleFrom(
directory: __DIR__,
namespace: 'billing',
deep: true,
loadViews: true,
loadLayouts: true,
loadComponents: true,
loadTypeScript: true,
);
}
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'));
}
loadViewsFrom
See also: architecture
Deeply 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',
);
}
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',
);
}
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',
);
}
Using the example above, the component src/Billing/components/invoice/item.vue
can be auto-imported as <billing-invoice-item />
.
loadTypeScriptFilesFrom
See also: architecture
Specifies a directory that will be used to register auto-imports of TypeScript files. If the deep
argument is set to true
, nested TypeScript files will also be registered.
Usage
public function boot(Hybridly $hybridly): void
{
$hybridly->loadTypeScriptFilesFrom(
directory: __DIR__.'/utils',
deep: false,
);
}