F
Filament4mo 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
awcodes4mo ago
As long as your livewire components have a ‘data’ property I don’t see why this wouldn’t work.
Augus
AugusOP4mo 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
awcodes4mo ago
$resource or $record?
Augus
AugusOP4mo ago
Record :p
awcodes
awcodes4mo ago
static::$record or static::getRecord() Something like that.
Augus
AugusOP4mo ago
Lemme try
awcodes
awcodes4mo ago
Could be static::getResource()->getRecord() too. Don’t remember of the top of my head.
Augus
AugusOP4mo ago
All methods not found 😦
awcodes
awcodes4mo ago
Is this in a panel or stand alone infolist package?
Augus
AugusOP4mo ago
Its a panel
awcodes
awcodes4mo ago
static::getModel() if your are on the Resource class.
Augus
AugusOP4mo ago
Thats giving me "App\Models\Animal" So the model used I got it 😮
Solution
Augus
Augus4mo ago
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
public static function infolist(Infolist $infolist): Infolist
{
$record = $infolist->getRecord();
Augus
AugusOP4mo ago
This works Thanks to you @awcodes , you just gave me the insights to look a bit deeper <#
awcodes
awcodes4mo ago
Glad you found it. Trying to source dive on my phone. Sorry. 😂
Augus
AugusOP4mo ago
No problem, youve been a great help Thanks alot
Want results from more Discord servers?
Add your server