Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 16, 2024
1 parent 7a3e4ab commit db40886
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 30 deletions.
19 changes: 19 additions & 0 deletions app/Filament/Admin/Resources/MenuResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Filament\Admin\Resources;

use Datlechin\FilamentMenuBuilder\Resources\MenuResource as BaseMenuResource;

class MenuResource extends BaseMenuResource
{
protected static bool $isScopedToTenant = false;

protected static ?int $navigationSort = 33;

public static function getNavigationGroup(): ?string
{
return __('app.navigation.admin');
}
}
15 changes: 14 additions & 1 deletion app/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

use App\Concerns\HasSlug;
use Database\Factories\PageFactory;
use Datlechin\FilamentMenuBuilder\Concerns\HasMenuPanel;
use Datlechin\FilamentMenuBuilder\Contracts\MenuPanelable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Page extends Model implements HasMedia
class Page extends Model implements HasMedia, MenuPanelable
{
/** @use HasFactory<PageFactory> */
use HasFactory;
use HasSlug;
use HasMenuPanel;
use InteractsWithMedia;

protected static string $factory = PageFactory::class;
Expand All @@ -25,4 +28,14 @@ class Page extends Model implements HasMedia
'slug',
'content',
];

public function getMenuPanelTitleColumn(): string
{
return 'title';
}

public function getMenuPanelUrlUsing(): callable
{
return fn (self $model) => $model->url;
}
}
16 changes: 16 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

use App\Filament\Admin\Pages\Auth\Login;
use App\Filament\Admin\Resources\ElectionResource;
use App\Filament\Admin\Resources\MenuResource;
use App\Models\Election;
use App\Models\Page;
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\MenuPanel\ModelMenuPanel;
use Filament\Facades\Filament;
use Filament\Forms\Components\DateTimePicker;
use Filament\Http\Middleware\Authenticate;
Expand Down Expand Up @@ -55,6 +59,18 @@ public function panel(Panel $panel): Panel
BreezyCore::make()
->myProfile(slug: 'profile')
->enableTwoFactorAuthentication(),

FilamentMenuBuilderPlugin::make()
->usingResource(MenuResource::class)
->addLocations([
'header' => 'Header',
'footer' => 'Footer',
])
->addMenuPanels([
ModelMenuPanel::make()
->model(Page::class),

]),
])
->viteTheme('resources/css/filament/common/theme.css')
->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources')
Expand Down
19 changes: 5 additions & 14 deletions app/View/Components/NavigationItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@

namespace App\View\Components;

use Closure;
use Datlechin\FilamentMenuBuilder\Models\MenuItem;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Route;
use Illuminate\View\Component;

class NavigationItem extends Component
{
public string $route;
public MenuItem $item;

public string $label;

public function __construct(string $route, string $label)
{
$this->route = $route;
$this->label = $label;
}

public function isCurrent(): bool
public function __construct(MenuItem $item)
{
return Route::currentRouteName() === $this->route;
$this->item = $item;
}

public function render(): View|Closure|string
public function render(): View
{
return view('components.navigation-item');
}
Expand Down
22 changes: 17 additions & 5 deletions app/View/Components/Site/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace App\View\Components\Site;

use App\Enums\Time;
use Datlechin\FilamentMenuBuilder\Models\Menu;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\Component;

class Header extends Component
Expand All @@ -18,11 +21,20 @@ public function __construct(bool $timeline = false)
{
$this->timeline = $timeline;

$this->menuItems = collect([
'front.index' => __('app.navigation.home'),
// 'about' => __('app.navigation.about'),
// 'partners' => __('app.navigation.partners'),
]);
$this->menuItems = $this->getMenuItems();
}

protected function getMenuItems(): Collection
{
return Cache::remember('header-menu', Time::DAY_IN_SECONDS, function () {
$menu = Menu::location('header');

if (blank($menu)) {
return collect();
}

return $menu->menuItems;
});
}

public function render(): View
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"awcodes/filament-tiptap-editor": "^3.4",
"blade-ui-kit/blade-icons": "^1.7",
"codeat3/blade-google-material-design-icons": "^1.19",
"datlechin/filament-menu-builder": "^0.6.0",
"filament/filament": "^3.2",
"filament/spatie-laravel-media-library-plugin": "^3.2",
"haydenpierce/class-finder": "^0.5.3",
Expand Down
76 changes: 75 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config/filament-menu-builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

return [
'tables' => [
'menus' => 'menus',
'menu_items' => 'menu_items',
'menu_locations' => 'menu_locations',
],
];
54 changes: 54 additions & 0 deletions database/migrations/0001_01_30_000010_create_menus_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

use Datlechin\FilamentMenuBuilder\Enums\LinkTarget;
use Datlechin\FilamentMenuBuilder\Models\Menu;
use Datlechin\FilamentMenuBuilder\Models\MenuItem;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create(config('filament-menu-builder.tables.menus'), function (Blueprint $table) {
$table->id();
$table->string('name');
$table->boolean('is_visible')->default(true);
$table->timestamps();
});

Schema::create(config('filament-menu-builder.tables.menu_items'), function (Blueprint $table) {
$table->id();

$table->foreignIdFor(Menu::class)
->constrained()
->cascadeOnDelete();

$table->foreignIdFor(MenuItem::class, 'parent_id')
->nullable()
->constrained($table->getTable())
->nullOnDelete();

$table->nullableMorphs('linkable');
$table->string('title');
$table->string('url')->nullable();
$table->string('target', 10)->default(LinkTarget::Self);
$table->integer('order')->default(0);
$table->timestamps();
});

Schema::create(config('filament-menu-builder.tables.menu_locations'), function (Blueprint $table) {
$table->id();

$table->foreignIdFor(Menu::class)
->constrained()
->cascadeOnDelete();

$table->string('location')->unique();
$table->timestamps();
});
}
};
Loading

0 comments on commit db40886

Please sign in to comment.