F
Filament3mo 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;
}
<?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>
<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(),
])
])
->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
3 Replies
Jpac14
Jpac14OP2mo ago
Any ideas on how to do this?
Vp
Vp2mo ago
Try like this 'url' => (fn () => AddPointsByStudent::getUrl()) or just pass the string 'url' => '/admin/student..url'
Roberto S.
Roberto S.7d ago
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');
CompanyResource::getUrl('edit', ['record' => 1], panel: 'management');
Or you can do this too:
$route = Filament::getPanel('management')->getUrl(CompanyResource::class, 'edit', ['record' => 1]);
$route = Filament::getPanel('management')->getUrl(CompanyResource::class, 'edit', ['record' => 1]);
Want results from more Discord servers?
Add your server