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/ */
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;
}}
}
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(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');
}
}