Hide a resource widget based on the resource status
Hey everyone. I found the option to hide a widget on a resource with this function:
public static function canView(): bool
The issue is that I want to only show the widget if the resource record/model is in a certain status. But I can't access the record because the function is static. Does anyone know a workaround?
What I would like to do but doesn't work:
Something that feels hacky that works:
5 Replies
Did you find a better sollution for this?
Could this work ?
There is an InteractsWithPageTable trait which you can use
For the widget
if you add that and add a use ExposesTableToWidgets; trait to the resource table you should get the same query executed passed to the widget
Then you can try to work with that query and do stuff
the problem is that your not in a object context. so you cant use $this
oh yea
I fixed it like this
protected function getHeaderWidgets(): array
{
$widgets = [];
// Access the current record using $this->record
$website = $this->record;
// Check if the relationship count is 0
if ($website && $website->websiteChecks()->count() === 0) {
$widgets[] = WebsiteResource\Widgets\WebsiteConnection::class;
}
return $widgets;
}
in the edit page, you can use conditions when building the array