Filament Quick Create

repository·5.x·Indexed 42 days ago

https://github.com/awcodes/filament-quick-create

A Filament plugin that adds a dropdown menu to the header, allowing users to quickly create new records from any part of the application. It supports resource filtering via includes() and excludes(), custom sorting, keyboard shortcuts, and flexible modal or slide-over configurations.

Tokens
6.9K
Snippets
34
Records
41
Agent score
51%

What's inside Filament Quick Create

  1. Overview of Quick Create

    5.x

    Quick Create adds a plus button to a Filament Panel header that provides a dropdown menu for creating records from anywhere in the application. This allows users to bypass navigating to a specific resource page before starting a creation process.

    • Authorization: The menu automatically respects Filament's built-in authorization. If a user's canCreate() check fails for a resource, that resource will not appear in the dropdown.
    • Tenancy: If tenancy is enabled, the menu will remain empty until a tenant is set.
  2. Style individual Quick Create menu entries via CSS

    5.x
    Each item in the Quick Create dropdown is assigned a CSS class derived from its label. For example, a resource with the label "Blog post" will render with the class quick-create-action-blog-post. You can use these classes in your theme to target and style specific entries without overriding the package's views.
  3. How Quick Create handles creation (Modal vs Page)

    5.x

    Quick Create determines how to present the creation form based on the resource's configuration:

    1. Dedicated Page: If the resource has a defined create page, Quick Create will navigate the user to that page.
    2. Modal: If the resource does not have a create page, Quick Create will open a modal containing the resource's form schema.

    You can override this behavior to force all resources to open in a modal using the plugin's configuration.

  4. Force every resource to open in a modal

    5.x

    By default, Quick Create decides whether to open a form in a modal or navigate to the resource's dedicated create page. You can override this behavior using alwaysShowModal() to ensure that no resource ever navigates away from the current page.

    use Awcodes\
    QuickCreate\QuickCreatePlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                QuickCreatePlugin::make()
                    ->alwaysShowModal(),
            ]);
    }
  5. Register the Quick Create plugin

    5.x

    To enable the plugin, register QuickCreatePlugin within your Filament Panel configuration using the plugins() method.

    use Awcodes//QuickCreate//QuickCreatePlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                QuickCreatePlugin::make(),
            ]);
    }
  6. Register package views with Tailwind

    5.x

    Because the menu is rendered from Blade views within the package, you must add the package path to your Tailwind configuration (typically in your custom theme's CSS file) so that the styles are generated.

    Warning: This requires a custom theme. If you haven't created one, follow the Filament documentation for Creating a custom theme.

    Add the following @source directive to your theme's CSS file. Adjust the number of ../ segments so the path correctly resolves to the vendor/awcodes/filament-quick-create/resources directory from your CSS file location.

    @source '../../../../vendor/awcodes/filament-quick-create/resources/**/*.blade.php';
  7. Install Quick Create

    5.x

    Install the package via Composer:

    composer require awcodes/filament-quick-create

    Important: If you are using Filament Panels without a custom theme, you must follow the Filament Docs to create one first.

    After setting up a custom theme, add the plugin's views to your theme CSS file to ensure styles are applied correctly:

    @source '../../../../vendor/awcodes/filament-quick-create/resources/**/*.blade.php';
  8. Exclude specific resources from the Quick Create menu

    5.x

    Use the excludes() method on the QuickCreatePlugin instance to remove specific resources from the Quick Create menu. This is the preferred method when you want most registered resources to appear in the menu, but need to hide a few specific ones. Note that Filament's standard authorization still applies: users will only see resources they have permission to create.

    use Awcodes\QuickCreate\QuickCreatePlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                QuickCreatePlugin::make()
                    ->excludes([
                        \App\Filament\Resources\UserResource::class,
                    ]),
            ]);
    }
  9. Register the QuickCreatePlugin in a Filament panel

    5.x

    To enable the Quick Create button, add QuickCreatePlugin::make() to the plugins() array of your Filament panel configuration. Note that plugins are per-panel; you must register it on every panel where you want the button to appear. By default, the menu will list every resource in the panel that the current user has permission to create.

    use Awcodes\QuickCreate\QuickCreatePlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                QuickCreatePlugin::make(),
            ]);
    }
  10. Change the sorting order of Quick Create menu entries

    5.x

    By default, Quick Create menu entries are sorted alphabetically by their label. You can control this behavior using sort() and sortBy():

    1. Disable alphabetical sorting: Pass false to sort() to maintain the order in which resources were registered with Filament.
    2. Sort by navigation order: Use sortBy('navigation') to match the order of the panel's navigation menu, utilizing each resource's navigation sort value.

    Note: sortBy() has no effect if sorting is disabled via sort(false). If an invalid value is passed to sortBy(), it will silently fall back to alphabetical sorting by label instead of throwing an error.

    // Keep the registration order instead of alphabetical
    QuickCreatePlugin::make()
        ->sort(false);
    
    // Sort based on Filament navigation order
    QuickCreatePlugin::make()
        ->sortBy('navigation');