F
Filament5mo ago
Augus

Add shared data to Infolist Livewire fields

I am using custom LiveWire components in my Infolist which look like so:
InfolistSection::make('RVO')
->schema([
Livewire::make(Details::class),
]),
InfolistSection::make('RVO Verblijfplaats(en)')
->collapsible()
->collapsed()
->schema([
Livewire::make(Locations::class),
]),
InfolistSection::make('RVO')
->schema([
Livewire::make(Details::class),
]),
InfolistSection::make('RVO Verblijfplaats(en)')
->collapsible()
->collapsed()
->schema([
Livewire::make(Locations::class),
]),
But both of those components are making an identical call in the mount() function like so:
public function mount(): void
{
$data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
$this->locations = $data ? $data['locations'] : false;
}
public function mount(): void
{
$data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
$this->locations = $data ? $data['locations'] : false;
}
and
public function mount(): void
{
$data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
$this->details = $data ? $data['details'] : false;
$this->translate();
}
public function mount(): void
{
$data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
$this->details = $data ? $data['details'] : false;
$this->translate();
}
So i wanted to create the variable $data in the infolist function but i am unable to access the resource here. Wanted situation:
public static function infolist(Infolist $infolist): Infolist
{
$data = (new Animal)->detail($resource->record->country_code, $resource->record->registration_number)->get();

return $infolist
->schema([
public static function infolist(Infolist $infolist): Infolist
{
$data = (new Animal)->detail($resource->record->country_code, $resource->record->registration_number)->get();

return $infolist
->schema([
And then i would call the Livewire components as followed:
InfolistSection::make('RVO')
->schema([
Livewire::make(Details::class, ['data' => $data]),
]),
InfolistSection::make('RVO')
->schema([
Livewire::make(Details::class, ['data' => $data]),
]),
All this would be to not call the same Animal function on one page (since this is an API call to a third party). How would i be able to create an $data variable like above to pass to multiple Livewire fields in my infolist?
Solution:
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
...
Jump to solution
16 Replies
awcodes
awcodes5mo ago
As long as your livewire components have a ‘data’ property I don’t see why this wouldn’t work.
Augus
AugusOP5mo ago
Well somehow I need the current $resource in the infolist function. But I’m not sure how to get the current resource in there.
awcodes
awcodes5mo ago
$resource or $record?
Augus
AugusOP5mo ago
Record :p
awcodes
awcodes5mo ago
static::$record or static::getRecord() Something like that.
Augus
AugusOP5mo ago
Lemme try
awcodes
awcodes5mo ago
Could be static::getResource()->getRecord() too. Don’t remember of the top of my head.
Augus
AugusOP5mo ago
All methods not found 😦
awcodes
awcodes5mo ago
Is this in a panel or stand alone infolist package?
Augus
AugusOP5mo ago
Its a panel
awcodes
awcodes5mo ago
static::getModel() if your are on the Resource class.
Augus
AugusOP5mo ago
Thats giving me "App\Models\Animal" So the model used I got it 😮
Solution
Augus
Augus5mo ago
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
Augus
AugusOP5mo ago
This works Thanks to you @awcodes , you just gave me the insights to look a bit deeper <#
awcodes
awcodes5mo ago
Glad you found it. Trying to source dive on my phone. Sorry. 😂
Augus
AugusOP5mo ago
No problem, youve been a great help Thanks alot
Want results from more Discord servers?
Add your server