nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

withCount is not working. #152

Open thirumalai56 opened 7 years ago

thirumalai56 commented 7 years ago

I have using two tables relation, everything working fine,but withcount relation not working.

$designs = Pin::search($search)->withCount(['tasks' => function($query) {
                $query->has('tasklist.project');
            }, 'likePin'])

This is urgent need of requirement,so any one help is useful. Thanks.

nonfuel commented 6 years ago

withCount first before searching.

like this..

$example = Questions::query(); $example = $questions->with('user', 'images', '...') ->withCount('something');

if(request('key')) { $example = $example->search(request('key'), null, true); }

$example = $example->get();