laravel-graphql icon indicating copy to clipboard operation
laravel-graphql copied to clipboard

Problem with custom query (where - like)

Open pyaehein opened this issue 6 years ago • 2 comments

I added custom query field 'nameLike' in my UsersQuery file. But its don't work with multiple query filter. It's only work when i use alone. Please help.

in args function

'nameLike' => ['name' => 'nameLike', 'type' => Type::string()]

in resolve function

else if (isset($args['nameLike'])) {
            return $user->where(function ($query) use ($args) {
                $query->where('name', 'like', '%' . $args['nameLike'] . '%');
            })->get();
        }

pyaehein avatar Apr 02 '18 11:04 pyaehein

But its don't work with multiple query filter

What do you mean by that?

Do you mean multiple e.g. space separated words in $args['nameLike'] should word as independent OR conditions? Then you've to manually split the string up and use ->orWhere, etc.

mfn avatar Jun 28 '18 23:06 mfn

You can use this package to creating an advanced search and custom filters.

https://github.com/mohammad-fouladgar/eloquent-builder

mohammad-fouladgar avatar Aug 20 '18 12:08 mohammad-fouladgar