承接 ganyicz/volt-namespace 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ganyicz/volt-namespace

最新稳定版本:0.0.2

Composer 安装命令:

composer require ganyicz/volt-namespace

包简介

Adds support for namespaces in Volt

README 文档

README

This is a (working) proof of concept.

Usage

Install the package via composer:

composer require ganyicz/volt-namespace 

Mount a new namespace in your VoltServiceProvider:

public function boot(): void { Volt::mount([ config('livewire.view_path', resource_path('views/livewire')), resource_path('views/pages'), ]); + VoltNamespace::mount('admin', resource_path('views/admin/livewire')); }

Use the namespace when rendering a volt component:

<livewire:admin:search-users />

The above will load a volt component from the following path:

/resources/views/admin/livewire/search-users.blade.php 

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:

Blade::anonymousComponentPath(resource_path('views/admin/components'), 'admin'); 

Combined, this allows us to have the following structure that keeps all related views together, including livewire, blade components and regular views:

resources └─ views └─ admin └─ auth └─ pages └─ livewire └─ components 

Whereas without namespaces, we would have to use subdirectories, which fragments the structure:

resources └─ views └─ admin └─ auth └─ pages └─ components └─ admin └─ livewire └─ admin 

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

  1. 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 />:

    volt-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:

    volt-livewire::admin:search-users 

    The package simply moves the primary namespace separator like this:

    volt-livewire:admin::search-users 

    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 in VoltNamespace::mount() method.

  2. 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

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固