area17 / twill

Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/cnWk7EFv8R.
https://twillcms.com
Apache License 2.0
3.63k stars 560 forks source link

feat: add searchQuery method to controller for finer control over the search #2614

Closed Tofandel closed 1 week ago

Tofandel commented 1 month ago

Description

Sometimes we need to be able to customize how the search works in a controller to search in a relation, or maybe to run a specific search, or to run a search that uses indexes

Now we can do just that and it's compatible with searchColumns:

        $this->setSearchColumns(['email', 'phone']);
        $this->setSearchQuery(
            fn (Builder $q, string $search) => $q
            ->orWhereHas('profile', fn (Builder $q) => $q
                ->where('first_name', 'like', "$search%")
                ->orWhere('last_name', 'like', "$search%")
            )
        );