© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
6 replies
Asmit

Custom field dynamic query

Here I have to create a custom field where I have to show suggestion by type [ char and variable name.
I want to make it generic where user should pass the query builder and suggest according to the user enter value.

DynamicVairable::make('dynamic_varibale')
  ->modifyingQuery(function () {
      return Notification::query();
  })
DynamicVairable::make('dynamic_varibale')
  ->modifyingQuery(function () {
      return Notification::query();
  })

But I don't know how to make it dynamic

class DynamicVairable extends Field
{
    protected string $view = 'forms.components.variable-field';

    public string $text = '';


    public Builder |\Closure $modifyingQuery;

    public function modifyingQuery(Builder | \Closure $modifyingQuery): static
    {
        $this->modifyingQuery = $modifyingQuery;

        return $this;
    }

    public function getModifyingQuery()
    {
        if($this->modifyingQuery instanceof \Closure) {
            return ($this->modifyingQuery)();
        }
        return $this->modifyingQuery;
    }

    public function searchVariable(string $value)
    {
        $this->getModifyingQuery()->where('variable', 'like', '%'.$value.'%')->get();
    }
}
class DynamicVairable extends Field
{
    protected string $view = 'forms.components.variable-field';

    public string $text = '';


    public Builder |\Closure $modifyingQuery;

    public function modifyingQuery(Builder | \Closure $modifyingQuery): static
    {
        $this->modifyingQuery = $modifyingQuery;

        return $this;
    }

    public function getModifyingQuery()
    {
        if($this->modifyingQuery instanceof \Closure) {
            return ($this->modifyingQuery)();
        }
        return $this->modifyingQuery;
    }

    public function searchVariable(string $value)
    {
        $this->getModifyingQuery()->where('variable', 'like', '%'.$value.'%')->get();
    }
}


This is my custom field
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
>
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
      <input x-model="state">
    </div>
</x-dynamic-component>
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
>
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
      <input x-model="state">
    </div>
</x-dynamic-component>

Please suggest some idea
I tried with livewire component but from field class I'm not able to pass query builder
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Custom Field passing dynamic data challenge
FilamentFFilament / ❓┊help
15mo ago
Dynamic field
FilamentFFilament / ❓┊help
3y ago
Dynamic Repeater Field
FilamentFFilament / ❓┊help
2y ago
dynamic field type
FilamentFFilament / ❓┊help
2y ago