Welcome and thank you for your interest in contributing to our project!. You must use this template to submit a Pull Request or it will not be accepted.
Motivation
[ ] Bug fix
[X] Enhancement
[ ] New feature
[ ] Breaking change
Description
This pull request improves the compatibility with Livewire Class Namespace configuration, allowing to create PowerGrid tables outside the app/Models directory.
To illustrate a use case, let's see an example where the application is organized in a Domain-Driven Design. Here is the directory structure:
By default, PowerGrid auto discovers Models living in the directory app/Models/. This PR, presents the new configuration key livewire-powergrid.auto_discover_models_paths, providing a simple way to register new directories to be scanned for Eloquent Models.
After publishing the configuration file by running php artisan vendor:publish --tag=livewire-powergrid-config, users can register directories as demonstrated below:
//config/livewire-powergrid.php
/*
|--------------------------------------------------------------------------
| Auto-Discover Models
|--------------------------------------------------------------------------
|
| PowerGrid will search for Models in the directories listed below.
| These Models be listed as options when you run the
| "artisan powergrid:create" command.
|
*/
'auto_discover_models_paths' => [
app_path('Models'),
base_path('Domain'),
],
Now, when running php artisan powergrid:create, the user will be presented with a list of Models found in the specified directories:
Select a Model or enter its Fully qualified name
› Domain\Client\Models\Client
Domain\User\Models\User
To maintain consistency when saving files, PowerGrid will follow the Livewire Config Key livewire.class_namespace.
To adjust the configuration, run: php artisan livewire:publish --config.
In our example, Livewire Namespace can be adjusted as follows:
//config/livewire.php
/*
|---------------------------------------------------------------------------
| Class Namespace
|---------------------------------------------------------------------------
|
| This value sets the root class namespace for Livewire component classes in
| your application. This value will change where component auto-discovery
| finds components. It's also referenced by the file creation commands.
|
*/
'class_namespace' => 'Domain',
When running php artisan powergrid:create, the user can enter the component name following the desired path. For example:
Enter a name for your new PowerGrid Component:
Client\Tables\ClientList
This will result in:
⚡ ClientList was successfully created at [Domain/Client/Tables/ClientList.php].
💡 include the ClientList component using the tag: <livewire:client.tables.client-list/>
👍 Please consider ⭐ starring ⭐ our repository. Visit: https://github.com/Power-Components/livewire-powergrid
As a reminder, the Domain directory must be added to autoload in composer.json:
⚡ PowerGrid - Pull Request
Welcome and thank you for your interest in contributing to our project!. You must use this template to submit a Pull Request or it will not be accepted.
Motivation
Description
This pull request improves the compatibility with Livewire Class Namespace configuration, allowing to create PowerGrid tables outside the
app/Models
directory.To illustrate a use case, let's see an example where the application is organized in a Domain-Driven Design. Here is the directory structure:
By default, PowerGrid auto discovers Models living in the directory
app/Models/
. This PR, presents the new configuration keylivewire-powergrid.auto_discover_models_paths
, providing a simple way to register new directories to be scanned for Eloquent Models.After publishing the configuration file by running
php artisan vendor:publish --tag=livewire-powergrid-config
, users can register directories as demonstrated below:Now, when running
php artisan powergrid:create
, the user will be presented with a list of Models found in the specified directories:To maintain consistency when saving files, PowerGrid will follow the Livewire Config Key
livewire.class_namespace
.To adjust the configuration, run:
php artisan livewire:publish --config
.In our example, Livewire Namespace can be adjusted as follows:
When running
php artisan powergrid:create
, the user can enter the component name following the desired path. For example:This will result in:
As a reminder, the
Domain
directory must be added to autoload incomposer.json
:Related Issue(s): https://github.com/Power-Components/livewire-powergrid/issues/1499
Documentation
This PR requires Documentation update?