Download the PHP package ganyicz/volt-namespace without Composer
On this page you can find all versions of the php package ganyicz/volt-namespace. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ganyicz/volt-namespace
More information about ganyicz/volt-namespace
Files in ganyicz/volt-namespace
Package volt-namespace
Short Description Adds support for namespaces in Volt
License MIT
Homepage https://github.com/ganyicz/volt-namespace
Informations about the package volt-namespace
Volt Namespaces
This is a (working) proof of concept.
Usage
Install the package via composer:
Mount a new namespace in your VoltServiceProvider:
Use the namespace when rendering a volt component:
The above will load a volt component from the following path:
Why
Using namespaces allows for a cleaner directory structure when maintaining multiple frontends in one repo. With Blade, we can already register a namespace for anonymous components like this:
Combined, this allows us to have the following structure that keeps all related views together, including livewire, blade components and regular views:
Whereas without namespaces, we would have to use subdirectories, which fragments the structure:
Disclaimer
This packge has only been tested in a single project with a specific setup and alters core functionalities of Laravel and Volt. This could have unintended consequences in your app. Use at your own risk.
If this functionality were to be added to the core of Volt, this could be achieved with a lot less hackery.
How it works
-
It binds a custom view finder that extends the
Illuminate\View\FileViewFinder
. This is required to load the correct view in the namespaced components.Volt uses a custom
volt-livewire
view namespace that contains all mounted paths and when a component is rendered it will try to load the following view for<livewire:search-users />
:The first part is the custom view namespace and the second part is the component name that Volt will look for in all mounted paths. In our case the name of the component would contain the "sub-namespace" like this:
The package simply moves the primary namespace separator like this:
Where
volt-livewire:admin
is a new view namespace that is registered by the pacakge when a volt namespace is mounted. This namespace contains the paths defined by the user inVoltNamespace::mount()
method. - It replaces the
Livewire\Volt\Precompilers\ExtractTemplate
precompiler to include the registered namespaced directories in the pre-compilation process.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Filip Ganyicz
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of volt-namespace with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0
livewire/livewire Version ^3.6
livewire/volt Version ^1.7
spatie/laravel-package-tools Version ^1.16