salmanalmajali/jokes-widget
A Laravel package that provides a ready-to-use jokes widget for your application. Quickly add a lightweight, customizable component to display jokes in views or dashboards, making it easy to inject a bit of humor without building the feature yourself.
The Filament Jokes Widget is a dashboard widget, not a full plugin with migrations or resources. Installation is therefore minimal:
Install the package:
composer require <vendor>/filament-jokes-widget
Confirm the exact package name and version constraints in the README / Packagist entry, and check the composer.json requirements for your Laravel and Filament versions.
Register the widget in your Filament panel provider:
use Filament\Panel;
use Vendor\FilamentJokesWidget\Widgets\JokesWidget;
public function panel(Panel $panel): Panel
{
return $panel
->widgets([
\Filament\Widgets\AccountWidget::class,
JokesWidget::class,
]);
}
Ensure your application locale is set. The widget uses the current locale to choose between Indonesian “bapak-bapak” jokes (id) and English dad jokes (en or fallback).
Visit your dashboard. You should see the joke card with a refresh button.
Where to look first:
app()->getLocale() vs. the Filament panel locale).lang/ or translation files if you want to adjust labels.First use case: Drop it on an internal admin dashboard for a bit of team morale. It is low-risk for internal tools; audit it before exposing it to customer-facing or regulated environments.
Global dashboard widget
Register the widget once in the panel provider’s ->widgets([...]) array. This makes it available on the default dashboard for all users who can access the panel.
Per-page or conditional placement
If you do not want the joke on every dashboard, render it from a custom page or another widget’s Blade view:
@livewire(\Vendor\FilamentJokesWidget\Widgets\JokesWidget::class)
You can also gate visibility with Filament’s standard widget authorization:
public static function canView(): bool
{
return auth()->user()?->isInternal() ?? false;
}
Check whether the package widget exposes canView(); if not, wrap it in your own subclass or render it conditionally in a custom page.
Locale strategy
id for Indonesian jokes and en for English dad jokes.app()->getLocale(), a panel-specific locale may not affect it unless your middleware sets the app locale.Refresh and caching
The refresh button is a Livewire action. Every click can trigger a new outbound request for English jokes. If your dashboard is busy or the external API is slow, wrap or cache the fetch:
$joke = Cache::remember(
'filament-jokes.'.app()->getLocale(),
now()->addMinutes(10),
fn () => /* package fetch call or your own HTTP client */,
);
If the package already caches, confirm the TTL and cache key in its source before adding another layer.
Testing
Fake the external API in tests to keep CI deterministic:
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
Http::fake([
'icanhazdadjoke.com/*' => Http::response([
'id' => 'test',
'joke' => 'A fake dad joke.',
'status' => 200,
], 200),
]);
Livewire::test(\Vendor\FilamentJokesWidget\Widgets\JokesWidget::class)
->assertSee('A fake dad joke.');
Also test the Indonesian path by setting the locale to id and asserting that no external HTTP call is made.
icanhazdadjoke.com. Dashboard rendering or refresh can fail or stall if the network is unavailable, the API is rate-limiting you, or egress is blocked in production. Check for timeouts and consider lazy-loading the widget so it does not block the initial dashboard render.id is treated specially. Locales such as in (legacy Indonesian code), id_ID, or regional variants may fall through to English. Normalise the locale before rendering if you need Indonesian jokes for those codes.Http::fake() will hit the real API. Fake it globally in your test suite or disable the widget in tests.How can I help you explore Laravel packages today?