PHPackages                             joserick/laravel-livewire-discover - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. joserick/laravel-livewire-discover

ActivePackage[Utility &amp; Helpers](/categories/utility)

joserick/laravel-livewire-discover
==================================

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

v1.3.2(3mo ago)2736.6k↓20%32GPL-3.0-or-laterPHP

Since Jan 25Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/joserick/laravel-livewire-discover)[ Packagist](https://packagist.org/packages/joserick/laravel-livewire-discover)[ RSS](/packages/joserick-laravel-livewire-discover/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (19)Used By (2)

[![laravel_livewire_discover.jpg](https://camo.githubusercontent.com/7d137efc9402bae30b5f6b41c6220dc664f61b52ccf096fc92e7906472754b5d/68747470733a2f2f6a6f73657269636b2e636f6d2f6c697665776972655f646973636f7665722e6a7067)](https://camo.githubusercontent.com/7d137efc9402bae30b5f6b41c6220dc664f61b52ccf096fc92e7906472754b5d/68747470733a2f2f6a6f73657269636b2e636f6d2f6c697665776972655f646973636f7665722e6a7067)

Laravel Livewire Discover
=========================

[](#laravel-livewire-discover)

[![Packagist Downloads](https://camo.githubusercontent.com/81424a3cbf69d2ca50c846c811a2e19494893d4560f529f1c7d3c67831ee9180/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f7665723f636f6c6f723d626c7565)](https://camo.githubusercontent.com/81424a3cbf69d2ca50c846c811a2e19494893d4560f529f1c7d3c67831ee9180/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f7665723f636f6c6f723d626c7565) [![GitHub License](https://camo.githubusercontent.com/06f484d1ef72395411d3c202a26a8735cbd1cd6a3dbd027bc9ba07c5f9521e0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f766572)](https://camo.githubusercontent.com/06f484d1ef72395411d3c202a26a8735cbd1cd6a3dbd027bc9ba07c5f9521e0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f766572) [![GitHub Release](https://camo.githubusercontent.com/4cbf22295e1926a42292b1cc7649037e77e5248fd513df4aa381a6f37a71cff4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f7665723f636f6c6f723d326461373131)](https://camo.githubusercontent.com/4cbf22295e1926a42292b1cc7649037e77e5248fd513df4aa381a6f37a71cff4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6a6f73657269636b2f6c61726176656c2d6c697665776972652d646973636f7665723f636f6c6f723d326461373131)

> Notice: [Migration to v1.0](https://github.com/joserick/laravel-livewire-discover#migration-to-v1) || [I need previous version (v0.3)](https://github.com/joserick/laravel-livewire-discover#i-need-for-v0.3.2)

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

Installation
------------

[](#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"](https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67)](https://www.buymeacoffee.com/joserick)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#enjoying-this-package-)

Config
------

[](#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](https://laravel.com/docs/blade#clipText-53)

```
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
---

[](#use)

Call Livewire Components:

```

```

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

[](#extra)

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

[](#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

[](#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

[](#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') //
