PHP code example of acerex / filament-menux

1. Go to this page and download the library: Download acerex/filament-menux library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acerex / filament-menux example snippets


FilamentMenuxPlugin::make()
    ->useStaticMenus([
        'header' => 'Header',
        'footer' => 'Footer',
        ])
    ->addStaticMenuItem('Home', '/')
    ->setNavigationLabel('Custom Menu Label')
    ->setPerPage(4)
    ->setActionModifierUsing(MenuxActionType::EDIT_MENU_ITEM, function (Action $action) {
        return $action->icon(Heroicon::MagnifyingGlassCircle);
    })
    ->addMenuxableModel(Post::class)
    ->setNavigationGroup('Custom Menu Group')
    ->addStaticMenuItem('Contact Us', '/contact-us')
    ->setLinkTargetEnum(linkTargetEnum: LinkTarget::class)
    ->addMenuxableModel(model: Page::class),


->plugins([
    \AceREx\FilamentMenux\FilamentMenuxPlugin::make()
])

\AceREx\FilamentMenux\FilamentMenuxPlugin::make()
    ->useStaticMenus([
        'slug'=>'label',
        'header'=>"Header"
    ], true)

->addStaticMenuItem('Home', '/', '_self')
 

->addGroupedMenuItems('Social Medias', [
    [
        'title' => 'Title',
        'url' => 'https://title.com',
        'target' => MenuxLinkTarget::BLANK,
    ],
    [
        'title' => 'Facebook',
        'url' => 'https://www.facebook.com',
        'target' => MenuxLinkTarget::SELF,
    ],
])

->addGroupedMenuItems('Social Medias', function () {
    return [
        [
            'title' => 'Title',
            'url' => 'https://title.com',
            'target' => MenuxLinkTarget::BLANK,
        ],
        [
            'title' => 'Facebook',
            'url' => 'https://www.facebook.com',
            'target' => MenuxLinkTarget::SELF,
        ],
    ];
})

->addMenuxableModel(Post::class)

\AceREx\FilamentMenux\Contracts\Interfaces\Menuxable

use Illuminate\Database\Eloquent\Builder;class Post extends Model implements Menuxable
{
    /** @use HasFactory<\Database\Factories\PostFactory> */
    use HasFactory;

    protected $fillable = [
        'title',
        'slug',
    ];

    public static function getMenuxLabel(): string
    {
        return 'Posts';
    }

    public function getMenuxTitle(): string
    {
        return $this->title;
    }

    public function getMenuxUrl(): string
    {
        return "https://www.google.com/{$this->slug}";
    }

    public function getMenuxTarget(): BackedEnum
    {
        return MenuxLinkTarget::SELF;
    }

    public static function getMenuxablesUsing(Builder $builder, $page, $perPage, ?string $q): Builder
    {
        if (filled($q)) {
            return $builder->whereLike('title', $q);
        }

        return $builder;
    }

    /**
    * This is optional. You can return an empty collection.
    * This will add a tab for each group so that you don't have to create multiple classes of Model when 
    * you only have a single table and want separate tabs for each filtering
    */
    public static function getMenuxableGroups(): Collection
    {
        $collection = collect();
        $collection->put('OnlyDoctors', function (Builder $builder, $page, $perPage, ?string $q) {
            $builder->where('role', 'Doctor');
            if(filled($q)){
                $builder->where('title', 'like', "%{$q}%");
            }
            return $builder;
        });

        return $collection;
    }}
}

->setMenuxablesPerPage(4)

->useCustomMenuModel(YourModel::class)

->useCustomMenuItemModel(CustomMenuItemModel::class)

->setNavigationGroup('Group')

->setNavigationLabel('Label')

->setNavigationIcon(\Filament\Support\Icons\Heroicon::AcademicCap)

->setMenuForm(CustomForm::class)

use AceREx\FilamentMenux\Filament\Resources\Menus\Schemas\MenuForm as BaseMenuForm;
use Filament\Forms\Components\TextInput;

class MenuForm extends BaseMenuForm
{
    public static function configure(): array
    {
        return [
            TextInput::make('name'),
        ];
    }
}


->setMenuForm(fn() => new class extends \App\Forms\MenuForm {

    public static function configure(): array
    {
        return [
            Section::make('Menu')
                ->collapsible()
                ->headerActions([
                    DeleteAction::make(),
                    Action::make('save')
                        ->label('Save')
                        ->button()
                        ->action('save'),
                ])
                ->schema([
                    TextInput::make('name')
                        ->label('Name')
                        ->

->setMenusTable(\App\Tables\MainMenusTable::class)

->setMenusTable(fn() => new class extends \AceREx\FilamentMenux\Filament\Resources\Menus\Tables\MenusTable {

    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label('Name')
                    ->sortable()
                    ->searchable(),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                \Filament\Actions\DeleteAction::make(),
                \Filament\Actions\EditAction::make()
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }

});

->setMenuItemForm(YourCustomMenuItemForm::class)

->setMenuItemForm(function (){
    return new class Extends \AceREx\FilamentMenux\Filament\Resources\Menus\Schemas\MenuItemForm {
        public function make() : array {
            return [
                \Filament\Forms\Components\TextInput::make('title')
            ]; 
        }
    }
})

enum MenuxActionType: string
{
    /**
     * Used in menu items builder inside the action group.
     */
    case DELETE_MENU_ITEM = 'delete-item';

    /**
     *Used in the menu items builder to delete the selected items.
     */
    case DELETE_SELECTED_MENU_ITEMS = 'delete-selected-items';

    /**
     * Used in menu items builder inside the action group.
     */
    case DUPLICATE__MENU_ITEM = 'duplicate-item';
    /**
     * Used in the menu items builder to edit created menu item.
     */
    case EDIT_MENU_ITEM = 'edit-item';

    /**
     * Used for adding a menu item not defined in the menu tabs.
     */
    case ADD_CUSTOM_MENU_ITEM = 'add-custom-item';

    /**
     * Used for adding a sub menu-item right under the item.
     */
    case CREATE_SUB_MENU_ITEM = 'create-sub-menu-item';
    /**
     * Used for creating the menu from the {@see ListMenus} or the resource header.
     */
    case CREATE_MENU = 'create-menu';
    /**
     * Used inside {@see MenusTable} actions. If you use your own Menus Table,
     * then it might be more practical to modify it inside that custom table.
     */
    case DELETE_MENU = 'delete-menu';
    /**
     * Used inside {@see MenusTable} actions. If you use your own Menus Table,
     * then it might be more practical to modify it inside that custom table.
     */
    case EDIT_MENU = 'edit-menu';
}

->setActionModifierUsing(MenuxActionType::DUPLICATE__MENU_ITEM, function (Action $action) {
    return $action
        ->icon(Heroicon::MagnifyingGlassCircle);

use AceREx\FilamentMenux\Contracts\Interfaces\ActionModifier;
use Filament\Actions\Action;

class CustomCreateSubMenuItemAction implements ActionModifier
{
    public function modify(Action $action): Action
    {
        return $action->label('Custom Gigidy');
    }
}

->setActionModifier(MenuxActionType::CREATE_SUB_MENU_ITEM, CustomCreateSubMenuItemAction::class)

->setLinkTargetEnum(linkTargetEnum: LinkTarget::class)

\Filament\Actions\Concerns\HasLabel

\AceREx\FilamentMenux\Contracts\Interfaces\HasStaticDefaultValue

enum LinkTarget: string implements HasLabel, HasStaticDefaultValue
{
    case SELF = 'self';

    public function getLabel(): string
    {
        return match ($this) {
            self::SELF => 'SELF'
        };
    }

    public static function getStaticDefaultValue(): HasStaticDefaultValue
    {
        return self::SELF;
    }

    public function getSomething(): string
    {
        return 'something';
    }
}

bash
php artisan vendor:publish --tag="filament-menux-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-menux-views"
css
@source '../../../../vendor/acerex/filament-menux/resources/views/**/*.blade.php';