Skip to content

Integration of Filament Admin to nWidart/laravel-modules: Create Admin panels for each Laravel Module

License

Notifications You must be signed in to change notification settings

marco76tv/filament-modules

 
 

Repository files navigation

Use FilamentPHP with nwiDart/laravel-modules

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads img_2.png img_3.png

This plugin provides you with a quick and working configuration to install multiple filament admin contexts in your modular laravel app (using laravel-modules).

Goal

The goal of this app is to enable you install multiple contexts of Filament Admin per module in your LaravelModules powered app.

For example, if you have two modules (Blog and Pos), you should be able to have filament installed in each module with separate resources as below:

  • Directory Modules/Blog/Filament should enable you to access the admin panel via http://yoururl/blog/admin
  • Directory Modules/Pos/Filament should enable you to access the admin panel via http://yoururl/pos/admin
  • We can even have another context under Modules/Pos/Filament2 should enable you to access the admin panel via http://yoururl/pos/admin2 or whichever path you configure for that context.

Each of the above directories should have their own distinct Pages, Resources and Widgets. Each of them also has a config under the module's Config folder allowing you to customize a number of parameters per context, e.g the path. Additionally, each of these can have its own customized login page which redirects back to the module.

You can read more about Multiple Context for Filament Here.

If this is your goal, then you are in the right place.

Installation

Before you proceed, this guide assumes that you have configured your app fully to work with Laravel Modules. If you haven't, follow the Laravel Modules Docs before proceeding.

You can install the package via composer:

composer require savannabits/filament-modules

Usage

To generate a new Filament Context, use the module:make-filament-context command. You can run php artisan module:make-filament-context -h to see the expected arguments.

#Option 1: Pick an existing module to use first, then run the command (similar to other laravel-modules commands)
php artisan module:use Blog
php artisan module:make-filament-context Filament # This will create the Filament context inside the blog module.

# Option 2: Pass the Module name as an argument. If the module does not exist, it will be automatically created.
php artisan module:make-filament-context Filament Blog # This will create the Filament context inside the blog module.

Directory Structure of the generated module:

img.png

Config:

The configuration for each of the generated contexts will be stored under the module's Config directory, e.g /Modules/Blog/Config/blog-filament.php in the above case. You can adjust the config to change several parameters, for example the admin panel path (by default it is admin).

The context's admin panel path

By default, you should be able to access your admin panel under the url http://yoururl/:yourModule/:yourPathConfig e.g http://yoururl/blog/admin in the above case. If you would like to change the path, you can change it under the corresponding config file.

The Context's Service Provider

This package automatically adds each of the generated context's service provider in providers' list in app.php config. Be sure to remove this Service Provider in case you delete the context.

Adding Pages/Resources/Widgets/RelationManagers to Module Context

You may now add filament resources in your FilamentTeams directories.

#Page: Pass the Module name as an argument and the name of page.
php artisan module:make-filament-page {module?} {name?} {--R|resource=} {--T|type=} {--F|force}

#Resources: Pass the Module name as an argument and the name of resources.
php artisan module:make-filament-resource {module?} {name?} {--soft-deletes} {--view} {--G|generate} {--S|simple} {--F|force}

#Widgets: Pass the Module name as an argument and the name of widget.
php artisan module:make-filament-widget {module?} {name?} {--R|resource=} {--C|chart} {--T|table} {--S|stats-overview} {--F|force}

#RelationManagers: Pass the Module name as an argument and the name of RelationManager.
php artisan module:make-filament-relation-manager {module?} {resource?} {relationship?} {recordTitleAttribute?} {--attach} {--associate} {--soft-deletes} {--view} {--F|force}

ContextualPage & ContextualResource traits

Pages:

namespace YourNamespace\Resources;

use Savannabits\FilamentModules\Concerns\ContextualPage;
use Filament\Pages\Page;

class Dashboard extends Page
{
    use ContextualPage;
}

Resources:

namespace YourNamespace\Resources;

use Savannabits\FilamentModules\Concerns\ContextualResource;
use Filament\Resources\Resource;

class UserResource extends Resource
{
    use ContextualResource;
}

Testing

composer test

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.

About

Integration of Filament Admin to nWidart/laravel-modules: Create Admin panels for each Laravel Module

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.0%
  • Other 1.0%