FilamentF
Filament17mo ago
Jpac14

How can I pass a URL to Widget on panel initialisation?

I want to add quicklinks to my dashboard and have created a custom widget to do so.
This is the code I have so far

<?php

namespace App\Filament\Widgets;

use Filament\Widgets\Widget;

class QuickLinkWidget extends Widget
{
    protected static string $view = 'widgets.quick-link-widget';

    public $title;
    public $icon;
    public $description;
    public $url;
}


<a href={{ $url }}>
  <x-filament-widgets::widget>
      <x-filament::section>
        <div class="flex gap-4 items-center">
          @svg($icon, 'h-8 w-8 text-gray-500')
          <div>
            <span class="font-bold">{{ $title }}</span>
            <p class="text-xs text-gray-500">{{ $description }}</p>
          </div>
        </div>
    </x-filament::section>
  </x-filament-widgets::widget>
</a>


            ->widgets([
                Widgets\AccountWidget::class,
                PointsTallyWidget::class,
                QuickLinkWidget::make([
                  'title' => 'Add Points',
                  'icon' => 'heroicon-o-plus-circle',
                  'description' => 'Add points to students',
                  'url' => AddPointsByStudent::getUrl(),
                ])
            ])
in AdminPanelProvider.php

But when I try this code I get this error Call to a member function generateRouteName() on null
https://flareapp.io/share/87nLqw4m#top

I am guessing it because the ::getUrl doesn't work to the panel is initalised is there any way to fix or get around this.

any help appreciated thanks
Flare
Call to a member function generateRouteName() on null - The error occurred at http://localhost:8000/admin
Was this page helpful?