webbingbrasil / filament-maps

Map widget for filament admin
MIT License
62 stars 20 forks source link

Why I do not see widget under admin dashboard ? #28

Open sergeynilov opened 4 months ago

sergeynilov commented 4 months ago

I have installed "webbingbrasil/filament-maps": "3.x-dev" into laravel 10 / filamentphp 3 app and during installation I selected next options :


$ php artisan make:filament-widget  BranchesMapWidget

┌ What type of widget do you want to create? ──────────────────┐
│ Custom                                                       │
└──────────────────────────────────────────────────────────────┘

┌ What is the resource you would like to create this in? ──────┐
│ BranchResource                                               │
└──────────────────────────────────────────────────────────────┘

┌ Where would you like to create this? ────────────────────────┐
│ The [admin] panel                                            │
└──────────────────────────────────────────────────────────────┘

INFO Filament widget [app/Filament/Resources/BranchResource/Widgets/BranchesMapWidget.php] created successfully.

INFO Make sure to register the widget in BranchResource::getWidgets(), and then again in getHeaderWidgets() or getFooterWidgets() of any BranchResource page.

Do not know if "Custom" type of widget is valid here ?

I expected to see widget under admin dashboard, asI selected [admin] panel.

I do not see maps also in BranchResource edit page.

I need maps both in BranchResource edit page and under admin dashboard with different set of points...

I looked some issues on the site and my widget is :

<?php

namespace App\Filament\Resources\BranchResource\Widgets;

use App\Filament\Resources\BranchResource;
use Filament\Widgets\Widget;

//class BranchesMapWidget extends Widget
use Illuminate\Contracts\Support\Htmlable;
use Webbingbrasil\FilamentMaps\Actions;
use Webbingbrasil\FilamentMaps\Marker;
use Webbingbrasil\FilamentMaps\Widgets\MapWidget;
class BranchesMapWidget  extends MapWidget
{
    public static string $resource = BranchResource::class;

    protected int | string | array $columnSpan = 1;

    protected bool $hasBorder = false;

    public array $mapOptions = ['center' => [0, 0], 'zoom' => 2];

    public Htmlable | string | null $heading = "Karte";

    public string | Htmlable | null $footer = "Mehr infos";

    public $record;

    protected static string $view = 'filament.resources.branch-resource.widgets.branches-map-widget';

    public function getMarkers(): array
    {
        dd($this->record); // I DO NOT SEE THIS OUTPUT
        return [
            Marker::make('pos2')->lat(-15.7942)->lng(-47.8822)->popup('Hello Brasilia!'),
        ];
    }

    public function getActions(): array
    {
        return [
            Actions\ZoomAction::make(),
            Actions\CenterMapAction::make()->zoom(2),
        ];
    }
}

also in my resources I try :

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Marker::make('pos2')->lat(-15.7942)->lng(-47.8822)->popup('Hello Brasilia!'),
                ...

    // Not sure if nect methods are valid
    public static function getWidgets(): array
    {
        return [
            BranchesMapWidget::class
        ];
    }

    public static function getHeaderWidgets(): array
    {
        return [
            BranchesMapWidget::class
        ];
    }

    public static function getFooterWidgets(): array
    {
        return [
            BranchesMapWidget::class
        ];
    }

    public static function BranchResource(): array
    {
        return [
            BranchesMapWidget::class
        ];
    }

Looks like I miscall the element... How correct ?

dmandrade commented 4 months ago

To display on the dashboard and resource edit page you need to create two widgets.

First one to resource and register it on two files:

  1. You must register the widget in your resource's getWidgets() method. - app/Filament/Resources/BranchResource.php
  2. Register it in getHeaderWidgets/getFooterWidgets on resource page - app/Filament/Resources/BranchResource/Pages

Now to display a widget on the dashboard, you need to create a new one and leave the resource option empty in the prompt, this will create a new widget in app/Filament/Widgets/ folder and display it on dashboard.

If the widgets shares code, use extends or traits.

sergeynilov commented 4 months ago

Thanks!