PHP code example of hoceineel / filament-sidebar-editor

1. Go to this page and download the library: Download hoceineel/filament-sidebar-editor 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/ */

    

hoceineel / filament-sidebar-editor example snippets


use HoceineEl\SidebarEditor\SidebarEditorPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(SidebarEditorPlugin::make());
}

use App\Models\User;
use HoceineEl\SidebarEditor\SidebarEditorPlugin;

SidebarEditorPlugin::make()
    ->storeOnTenant('navigation')
    ->authorize(fn (): bool => auth()->user()?->can('manage-sidebar') ?? false)
    ->slug('menu')
    ->navigationGroup('settings')
    ->navigationSort(45)
    ->pinnedItems(['dashboard', 'billing'])
    ->fixedMainGroup();

return [
    'table' => 'sidebar_editor_layouts',
];

[
    ['key' => 'sales', 'hidden' => false, 'items' => [
        ['key' => 'orders', 'hidden' => false],
        ['key' => 'coupons', 'hidden' => true],
    ]],
    ['key' => 'reports', 'hidden' => true, 'items' => []],
]

Schema::table('teams', fn (Blueprint $table) => $table->json('navigation')->nullable());

protected function casts(): array
{
    return ['navigation' => 'array'];
}

use Filament\Panel;
use HoceineEl\SidebarEditor\Contracts\LayoutStore;

class SettingsStore implements LayoutStore
{
    public function get(Panel $panel): ?array
    {
        return settings("sidebar.{$panel->getId()}");
    }

    public function put(Panel $panel, ?array $groups): void
    {
        settings()->set("sidebar.{$panel->getId()}", $groups);
    }
}

SidebarEditorPlugin::make()->store(SettingsStore::class);

SidebarEditorPlugin::make()->storeUsing(
    get: fn (Panel $panel): ?array => cache()->get("sidebar.{$panel->getId()}"),
    put: fn (?array $groups, Panel $panel) => cache()->forever("sidebar.{$panel->getId()}", $groups),
);

use HoceineEl\SidebarEditor\Pages\SidebarEditor;
use Livewire\Livewire;

it('hides coupons', function (): void {
    Livewire::test(SidebarEditor::class)
        ->call('toggleItem', 'sales', 'coupons')
        ->callAction('save');

    expect($team->fresh()->navigation['groups'])->not->toBeEmpty();
});
bash
php artisan vendor:publish --tag=sidebar-editor-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=sidebar-editor-config
php artisan vendor:publish --tag=sidebar-editor-translations
php artisan vendor:publish --tag=sidebar-editor-views