承接 joserick/laravel-livewire-discover 相关项目开发

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

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

joserick/laravel-livewire-discover

Composer 安装命令:

composer require joserick/laravel-livewire-discover

包简介

Discover and autoload multiples components of livewire by convention (componentNamespace)

README 文档

README

laravel_livewire_discover.jpg

Laravel Livewire Discover

Packagist Downloads GitHub License GitHub Release

Notice: Migration to v1.0 || I need previous version (v0.3)

Automatically discover and load/register multiple/different class namespaces for Livewire components.

Installation

You can add the package via composer:

composer require joserick/laravel-livewire-discover

And then install the package with artisan:

php artisan livewire-discover:install

Enjoying this package? "Buy Me A Coffee"

Config

Add to LivewireDiscoverServiceProvider.php

public function boot(): void
{
  // Load multiples namespace for Livewire components.
  Livewire::discovers([
    'my-components' => 'Namespaces\\Livewire',
    'new-components' => 'User\\Repository\\Livewire',
  ]);

  // Or individually
  Livewire::discover('my-components', 'Namespaces\\Livewire');
  Livewire::discover('new-components', 'User\\Repository\\Livewire');
}

Or if you like, use "componentNamespace" function as in Blade Templates

public function boot(): void
{
  // Load multiples namespace for Livewire components.
  Livewire::componentNamespace('Namespaces\\Livewire', 'my-components');
  Livewire::componentNamespace('User\\Repository\\Livewire', 'new-components');
  // ...
}

Or use the config: 'config/livewire-discover.php'

// Load the namespace to Livewire components.
'class_namespaces' => [
  // 'prefix' => 'class\\namespace',
  'my-components' => 'Namespaces\\Livewire',
  'new-components' => 'User\\Repository\\Livewire',
],

Use

Call Livewire Components:

<livewire:my-components.devices /> <!-- Class: Namespace\Livewire\Devices; -->
<livewire:new-components.auth.login /> <!-- Class: User\Repository\Livewire\Auth\Login; -->
<livewire:new-components.auth.register-admin /> <!-- Class: User\Repository\Livewire\Auth\RegisterAdmin; -->

Or use form Routes:

// Load Livewire Component from Route
use Namespaces\Livewire\Devices;
use User\Repository\Livewire\DevicesTable;

Route::get('/devices', Devices::class); // resolve name my-components.devices
Route::get('/devices_table', DevicesTable::class); // resolve name new-components.devices-table

"Obviously" you need to install the "layout" first for the Routes

php artisan livewire:layout

Extra

Displays the list of loaded namespaces (prefix, aliases and paths)

If you want to check if all the namespaces are loading correctly you can run:

php artisan livewire-discover:list

Which will show you a table with all the information:

Livewire-Discover namespaces list:

Prefix: 'my-components' (Namespaces\\Livewire)
There is no "class path" defined for the config for prefix 'my-components'
Getting the "class path" from the composer autoload file
+-----------------------+-----------------------------------------------+
| Alias                 | Paths                                         |
+-------------------------------------------+---------------------------+
| my-components.devices | /var/www/html/namespaces/livewire/devices.php |
+-----------------------+-----------------------------------------------+

Create your components quickly

You can create the files automatically using the following Artisan command. In the process it will ask you for the prefix to use.

php artisan livewire-discover:make RegisterAdmin
# Or
php artisan make:livewire-discover RegisterAdmin

If you prefer kebab-cased names, you can use them as well:

php artisan livewire-discover:make register-admin

You may use namespace syntax or dot-notation to create your components in sub-directories. For example, the following commands will create a RegisterAdmin component in the Auth sub-directory:

php artisan livewire-discover:make Auth\\RegisterAdmin
php artisan livewire-discover:make auth.register-admin

Also if you don't want it to constantly ask you which prefix to select you can pass it directly with the --prefix attribute

Manually configure the 'classpath' for component creation and listing

When automatically created components through the artisan livewire-discover:make this obtains the directory path based on 'Composer Autoload File' If for some reason it is not possible to do this, you can manually configure the path, adding it as the third parameter:

Livewire::discover(
    'my-components',
    'Namespaces\\Livewire',
    app_path('/Path/Livewire') // <-- Components directory path
);

Now when you create the component it will be created in the path you have specified.

Config 'view path' for component creation

Do you also want it to create the view at a specific route? Just add the view route and it will automatically create it, simple as that:

Livewire::discover(
    'my-components',
    'Namespaces\\Livewire',
    app_path('/Path/Livewire')
    resource_path('/views/path/livewire'), <-- Components views path
);

Remember that these are examples, you can specify any path within your project and it will create it.

Migration to v1

Rename Config File

The configuration file name has changed from laravel-livewire-discover.php to simply livewire-discover-php

Attributes Reversed

Replace Livewire::discover for Livewire::componentNamespace since the attributes in v1 are reversed but the componentNamespace function maintains the structure of previous versions.

Livewire::discover('Namespaces\\Livewire', 'my-components');

to

Livewire::componentNamespace('Namespaces\\Livewire', 'my-components');

or in any case to maintain the use of the discover() function you can invert the parameters.

Dot-Notation

Change in concatenation of prefixes with class name, previously it was concatenated using the "-" notation, now the dot-notation is used, so it must be changed in all calls to Livewire-Discover components

<livewire:components-devices />

to

<livewire:components.devices />

I need for v0.3.2

composer require joserick/laravel-livewire-discover:0.3.2

License

The GNU Public License (GPLv3). Please see License File for more information.

joserick/laravel-livewire-discover 适用场景与选型建议

joserick/laravel-livewire-discover 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41.39k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2024 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 joserick/laravel-livewire-discover 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 joserick/laravel-livewire-discover 我们能提供哪些服务?
定制开发 / 二次开发

基于 joserick/laravel-livewire-discover 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 41.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 27
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-01-25