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

7 messages · Page 1 of 1 (latest)

main shell
#

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;
}```

```html
<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>```

```php
            ->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
restive escarpBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

main shell
#

Any ideas on how to do this?

sudden radish
#

Try like this 'url' => (fn () => AddPointsByStudent::getUrl())

#

or just pass the string 'url' => '/admin/student..url'

ancient hedge
#

This error typically occurs when Filament cannot find the correct panel configuration. We need to specify the panel to which the resource belongs. In Filament 3, each resource belongs to a specific panel.

In my case I use something like this:

CompanyResource::getUrl('edit', ['record' => 1], panel: 'management');

Or you can do this too:

$route = Filament::getPanel('management')->getUrl(CompanyResource::class, 'edit', ['record' => 1]);
main shell
#

Bump anyways to solve this one?