F
Filament7mo 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
LeandroFerreira7mo ago
$getRecord() ?
Pscl
PsclOP7mo ago
Undefined variable $getRecord 😄
LeandroFerreira
LeandroFerreira7mo ago
Sorry, you can use getRecord in the view
Pscl
PsclOP7mo 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
LeandroFerreira7mo ago
use InteractsWithRecord;

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

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