F
Filamentβ€’2mo ago
Pscl

How to get and use current model of view page within a widget?

protected function getData(): array {
$currentModel = ...?
//...
}
protected function getData(): array {
$currentModel = ...?
//...
}
I want t load stats of a model... hmm. thanks!
9 Replies
LeandroFerreira
LeandroFerreiraβ€’2mo ago
$getRecord() ?
Pscl
Psclβ€’2mo ago
Undefined variable $getRecord πŸ˜„
LeandroFerreira
LeandroFerreiraβ€’2mo ago
Sorry, you can use getRecord in the view
Pscl
Psclβ€’2mo ago
How?
class ContractStatsWidget extends BaseWidget
{
public $record;

public function mount($record): void
{
$this->record = $record;
}
class ContractStatsWidget extends BaseWidget
{
public $record;

public function mount($record): void
{
$this->record = $record;
}
` This is working in my StatsWidget, but not in ChartWidget.
LeandroFerreira
LeandroFerreiraβ€’2mo ago
use InteractsWithRecord;

protected function getData(): array {
$currentModel = $this->getRecord();
}
use InteractsWithRecord;

protected function getData(): array {
$currentModel = $this->getRecord();
}
Pscl
Psclβ€’2mo ago
This was easy... could you guide me on how I could have find it in documentation? Thanks!
Pscl
Psclβ€’2mo ago
Thanks. Maybe an idea to add it to the documentation somewhere.
LeandroFerreira
LeandroFerreiraβ€’2mo ago
You can make a PR ✌️
Want results from more Discord servers?
Add your server
More Posts