PHP code example of datlechin / filament-menu-builder
1. Go to this page and download the library: Download datlechin/filament-menu-builder 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/ */
datlechin / filament-menu-builder example snippets
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->showCustomLinkPanel(false)
)
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->showCustomTextPanel()
)
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\StaticMenuPanel;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuPanels([
StaticMenuPanel::make()
->add('Home', url('/'))
->add('Blog', url('/blog')),
])
)
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\StaticMenuPanel;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuPanels([
StaticMenuPanel::make()
->addMany([
'Home' => url('/'),
'Blog' => url('/blog'),
])
])
)
use Datlechin\FilamentMenuBuilder\Concerns\HasMenuPanel;
use Datlechin\FilamentMenuBuilder\Contracts\MenuPanelable;
use Illuminate\Database\Eloquent\Model;
class Category extends Model implements MenuPanelable
{
use HasMenuPanel;
public function getMenuPanelTitleColumn(): string
{
return 'name';
}
public function getMenuPanelUrlUsing(): callable
{
return fn (self $model) => route('categories.show', $model->slug);
}
}
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\ModelMenuPanel;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuPanels([
ModelMenuPanel::make()
->model(\App\Models\Category::class),
])
)
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->addMenuFields([
Toggle::make('is_logged_in'),
])
->addMenuItemFields([
TextInput::make('classes'),
])
)
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table(config('filament-menu-builder.tables.menus'), function (Blueprint $table) {
$table->boolean('is_logged_in')->default(false);
});
Schema::table(config('filament-menu-builder.tables.menu_items'), function (Blueprint $table) {
$table->string('classes')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table(config('filament-menu-builder.tables.menus'), function (Blueprint $table) {
$table->dropColumn('is_logged_in');
});
Schema::table(config('filament-menu-builder.tables.menu_items'), function (Blueprint $table) {
$table->dropColumn('classes');
});
}
}
namespace App\Filament\Plugins\Resources;
use Datlechin\FilamentMenuBuilder\Resources\MenuResource as BaseMenuResource;
class MenuResource extends BaseMenuResource
{
protected static ?string $navigationGroup = 'Navigation';
public static function getNavigationBadge(): ?string
{
return number_format(static::getModel()::count());
}
}
use App\Filament\Plugins\Resources\MenuResource;
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->usingResource(MenuResource::class)
)
use App\Models\Menu;
use App\Models\MenuItem;
use App\Models\MenuLocation;
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
$panel
...
->plugin(
FilamentMenuBuilderPlugin::make()
->usingMenuModel(Menu::class)
->usingMenuItemModel(MenuItem::class)
->usingMenuLocationModel(MenuLocation::class)
)
use Datlechin\FilamentMenuBuilder\Models\Menu;
$menu = Menu::location('primary');