awcodes / filament-quick-create
Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items.
Fund package maintenance!
awcodes
Installs: 77 687
Dependents: 7
Suggesters: 0
Security: 0
Stars: 172
Watchers: 4
Forks: 27
Open Issues: 0
Requires
- php: ^8.1
- filament/filament: ^v3.2.23
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- spatie/laravel-ray: ^1.26
- 3.x-dev
- v3.6.1
- v3.6.0
- v3.5.0
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.0
- v3.0.0-beta.3
- v3.0.0-beta.2
- v3.0.0-beta.1
- v3.0.0-alpha2
- v3.0.0-alpha1
- 2.x-dev
- v2.1.1
- v2.1.0
- v2.0.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-fix/fallback-create-another
- dev-feat/disable-create-another
- dev-fix/tenancy
This package is auto-updated.
Last update: 2024-11-07 15:47:36 UTC
README
Plugin for Filament Admin Panel that adds a dropdown menu to the header to quickly create new items from anywhere in your app.
Installation
Install the package via composer
composer require awcodes/filament-quick-create
In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.
Note If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.
Add the plugin's views to your tailwind.config.js
file.
content: [ '<path-to-vendor>/awcodes/filament-quick-create/resources/**/*.blade.php', ]
Usage
By default, Quick Create will use all resources that are registered with current Filament context. All resources will follow the authorization used by Filament, meaning that if a user doesn't have permission to create a record it will not be listed in the dropdown.
Registering the plugin
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make(), ]) }
Warning Excludes and includes are not meant to work together. You should use one or the other, but not both.
Excluding Resources
Excluding resources will filter them out of the registered resources to prevent them from displaying in the dropdown.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->excludes([ \App\Filament\Resources\UserResource::class, ]), ]) }
Including Resources
Sometimes, it might be easier to only include some resources instead of filtering them out. For instance, you have 30 resources but only want to display 3 to 4 in the dropdown.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->includes([ \App\Filament\Resources\UserResource::class, ]), ]) }
Sorting
By default, Quick Create will sort all the displayed options in descending order by Label. This can be disabled should you choose. In which case they will be displayed in the order they are registered with Filament.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->sort(false), ]) }
Sorting by resource navigation
By default, Quick Create will sort all the displayed options by Label. This can be changed to resource navigation sort should you choose. In which case they will be displayed in the order they are displayed in the navigation.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->sortBy('navigation'), ]) }
Registering keybindings
You can attach keyboard shortcuts to trigger the Quick Create dropdown. To configure these, pass the keyBindings() method to the configuration:
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->keyBindings(['command+shift+a', 'ctrl+shift+a']), ]) }
Create Another
By default, the ability to create another record will respect the settings of your 'create record' or 'list records' create action. This can be overridden to either enable or disable it for all resources with the createAnother()
method.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->createAnother(false), ]) }
Appearance
Rounded
By default, the Quick Create button will be fully rounded if you would like to have a more square button you can disable the rounding with the rounded()
method.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->rounded(false), ]) }
Hiding Icons
If you prefer to not show icons for the items in the menu you can disable them with the hiddenIcons()
method.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->hiddenIcons(), ]) }
Setting a label
If you prefer to show a label with the plus icon you can set it using the label()
method and passing your label to it.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->label('New'), ]) }
Slide Overs
By default, Quick Create will render simple resources in a standard modal. If you would like to render them in a slide over instead you may use the slideOver()
modifier to do so.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->slideOver(), ]) }
Hiding Quick Create
By default, Quick Create is visible if there are registered resources. If you would like to hide it you may use the hidden()
modifier to do so.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->hidden(fn() => Filament::getTenant()->requiresOnboarding()), ]) }
Render Plugin on a Custom Panel Hook
By default, Quick Create plugin renders using 'panels::user-menu.before'
Filament Panel Render Hook. If you would like to customize this to render at a different render hook, you may use the renderUsingHook(string $panelHook)
modifier to do so. You may read about the available Render Hooks in Filament PHP here
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; use Filament\View\PanelsRenderHook; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->renderUsingHook(PanelsRenderHook::SIDEBAR_NAV_END), ]) }
Forcing all resources to use modals
Quick create will automatically determine if it should redirect to a create page or to show the form in a modal based on the resource. If you prefer to force all items to be show in a modal you can do so with the alwaysShowModal()
modifier.
use Awcodes\FilamentQuickCreate\QuickCreatePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ QuickCreatePlugin::make() ->alwaysShowModal(), ]) }