use BernskioldMedia\Laravel\Widgets\Concerns\HasTitle;
class MyWidget extends Widget
{
use HasTitle;
protected static function defaultTitle(): string
{
return 'My Widget';
}
}
use BernskioldMedia\Laravel\Widgets\Concerns\HasDescription;
class MyWidget extends Widget
{
use HasDescription;
protected static function defaultDescription(): string
{
return 'My Widget';
}
}
use BernskioldMedia\Laravel\Widgets\Concerns\Filterable;
use BernskioldMedia\Laravel\Widgets\Contracts\SupportsFilters;
class MyWidget extends Widget implements SupportsFilters
{
use Filterable;
protected static function defaultFilters(): array
{
return [
'startDate' => today()->subDays(7),
'endDate' => today(),
];
}
}
use BernskioldMedia\Laravel\Widgets\Concerns\Filterable;
use BernskioldMedia\Laravel\Widgets\Contracts\SupportsFilters;
class MyWidget extends Widget implements SupportsFilters
{
use Filterable;
protected static function forcedFilters(): array
{
return [
'startDate' => today()->subDays(7),
'endDate' => today(),
];
}
}
// Get all filters
$this->getFilters();
// Get a specific filter (or null if it doesn't exist)
$this->getFilter('startDate');
// Get a specific filter or return a custom value
$this->getFilter('startDate', today());
// Set a filter
$this->setFilter('startDate', today());
// Set multiple filters
$this->setFilters([
'startDate' => today(),
'endDate' => today()->addDays(7),
]);
// Check if a filter exists
$this->hasFilter('startDate');
// Remove a filter
$this->removeFilter('startDate');
// Clear all custom filters.
$this->resetFilters();
protected static function view(): string
{
return 'widgets.my-widget';
}