how to get result function custom field?

I make custom field how to fetch data i want make table with pagination custom.
<?php

namespace App\Filament\Forms\Components;

use App\Models\Outlet;
use Filament\Forms\Components\Field;

class OutletMapPicker extends Field
{
protected string $view = 'filament.forms.components.outlet-map-picker';


public function getOutletPage($page = 1, $search = null): array
{
$query = Outlet::query()->select('id', 'name', 'latitude', 'longitude');

if ($search) {
$query->where('name', 'like', "%{$search}%");
}

return $query->paginate(10, ['*'], 'page', $page)
->through(fn ($o) => [
'id' => $o->id,
'name' => $o->name,
'latitude' => $o->latitude,
'longitude' => $o->longitude,
])->toArray();
}

protected function setUp(): void
{
parent::setUp();

$this->default([]);
}
}
<?php

namespace App\Filament\Forms\Components;

use App\Models\Outlet;
use Filament\Forms\Components\Field;

class OutletMapPicker extends Field
{
protected string $view = 'filament.forms.components.outlet-map-picker';


public function getOutletPage($page = 1, $search = null): array
{
$query = Outlet::query()->select('id', 'name', 'latitude', 'longitude');

if ($search) {
$query->where('name', 'like', "%{$search}%");
}

return $query->paginate(10, ['*'], 'page', $page)
->through(fn ($o) => [
'id' => $o->id,
'name' => $o->name,
'latitude' => $o->latitude,
'longitude' => $o->longitude,
])->toArray();
}

protected function setUp(): void
{
parent::setUp();

$this->default([]);
}
}
11 Replies
Kaesa Lyrih
Kaesa LyrihOP3mo ago
$wire undifiend i dont know how to fetchData -_- or i make livewire component?
Dennis Koch
Dennis Koch3mo ago
It's not a Livewire component. Just a Blade component. You should be able to run that function via $getOutletPage()
Kaesa Lyrih
Kaesa LyrihOP3mo ago
Filament/FIeld is not livewire component? Solution if wanna make pagination table make livewire component and in field include livewire component?
Dennis Koch
Dennis Koch3mo ago
No. If every field was a Livewire component the performance would be really bad. You can include Livewire components in your form via Forms\Components\Livewire "field"
Kaesa Lyrih
Kaesa LyrihOP3mo ago
i can make like this?
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field">

<x-livewire:outlet-table-map-picker :state="$wire.$entangle(@js($getStatePath()))"/>

</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field">

<x-livewire:outlet-table-map-picker :state="$wire.$entangle(@js($getStatePath()))"/>

</x-dynamic-component>
how to connected state field into custom livewire component? input using wire:model if livewire component? how entangle it? owh okay, new knowlage for me. Page = Livewire Component, Field & Infolist & Coloums = Blade Component.
Dennis Koch
Dennis Koch3mo ago
Sorry, I'm not sure about that one.
Kaesa Lyrih
Kaesa LyrihOP3mo ago
$getOutletPage() can call in initial how to call again? <button @click=$getOutletPage(currentPage + 1) />
Dennis Koch
Dennis Koch3mo ago
It's not a Livewire component. You can't use Livewire features. All the methods would need to be on the page. For example via a trait.
Kaesa Lyrih
Kaesa LyrihOP3mo ago
i see, i need include livewire component in field. if want make pagination filament/field via livewire component.
Dennis Koch
Dennis Koch3mo ago
You can either create a normal field, that needs a trait on the page that provides the methods for it. Or you create a LW component that paginates by reloading the parent component or page.
Kaesa Lyrih
Kaesa LyrihOP3mo ago
thanks, maybe make LW component make easy, and can reuse again out panel filament.

Did you find this page helpful?