#how to get result function custom field?

19 messages · Page 1 of 1 (latest)

fickle minnow
#

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([]);
    }
}
fringe roverBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

fickle minnow
#

$wire undifiend
i dont know how to fetchData -_- or i make livewire component?

lime siren
#

It's not a Livewire component. Just a Blade component. You should be able to run that function via $getOutletPage()

fickle minnow
#

Solution if wanna make pagination table make livewire component and in field include livewire component?

lime siren
lime siren
fickle minnow
#

how to connected state field into custom livewire component?

#

input using wire:model if livewire component? how entangle it?

fickle minnow
lime siren
#

Sorry, I'm not sure about that one.

fickle minnow
lime siren
#

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.

fickle minnow
#

if want make pagination filament/field via livewire component.

lime siren
#

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.