searchable icon indicating copy to clipboard operation
searchable copied to clipboard

Laravel 5.2 Support

Open rohitbhirud opened this issue 8 years ago • 14 comments

Pagination not working... Gives error if search query returns zero results : ErrorException in Collection.php line 1040: Undefined offset: 0

rohitbhirud avatar Jan 08 '16 16:01 rohitbhirud

+1

JustSteveKing avatar Jan 12 '16 14:01 JustSteveKing

+1

juan55860 avatar Jan 15 '16 21:01 juan55860

+1

essivision avatar Jan 18 '16 15:01 essivision

+1

r3k4 avatar Jan 22 '16 16:01 r3k4

WARNING: this is not a solution! This works for some cases and doesn't work for others. Please search for other solutions, maybe here https://github.com/nicolaslopezj/searchable/issues/73


I believe I have the same issue with pagination. In laravel 5.2 when using pagination bindings are lost and query throws an exception:

SQLSTATE[HY000]: General error: 2031 (SQL: select count(*) as aggregate from (select ...

Searchable adds bindings for select group, but then in https://github.com/illuminate/database/blob/master/Query/Builder.php#L1548 bindings are temporary removed for select group so query throws exception.

protected function backupFieldsForCount()
    {
        foreach (['orders', 'limit', 'offset', 'columns'] as $field) {
            $this->backups[$field] = $this->{$field};
            $this->{$field} = null;
        }
        foreach (['order', 'select'] as $key) {
            $this->bindingBackups[$key] = $this->bindings[$key];
            $this->bindings[$key] = [];
        }
    }

So I've replaced select to where in https://github.com/nicolaslopezj/searchable/blob/master/src/SearchableTrait.php#L308 and pagination query started to work.

    protected function addBindingsToQuery(Builder $query, array $bindings) {
        $count = $this->getDatabaseDriver() != 'mysql' ? 2 : 1;
        for ($i = 0; $i < $count; $i++) {
            foreach($bindings as $binding) {
                $type = $i == 0 ? 'where' : 'having';
                $query->addBinding($binding, $type);
            }
        }
    }

I didn't create PR because not sure the reason why select was selected there.

antongorodezkiy avatar Feb 24 '16 12:02 antongorodezkiy

+1 for this

gcphost avatar Feb 29 '16 02:02 gcphost

+1

SUKOHI avatar Mar 04 '16 17:03 SUKOHI

+1

MatthewHallCom avatar Mar 06 '16 00:03 MatthewHallCom

+1

4riel avatar Mar 09 '16 00:03 4riel

+1

axhello avatar Mar 11 '16 09:03 axhello

Hi, nicolaslopezj. I know this way is not smart but I guess there's no way to use raw query like this because this issue is caused by laravel core.

protected function getSearchQuery(Builder $query, $column, $relevance, array $words, $relevance_multiplier, $pre_word = '', $post_word = '') { $like_comparator = $this->getDatabaseDriver() == 'pgsql' ? 'ILIKE' : 'LIKE'; $cases = []; foreach ($words as $word) { $case = $this->getCaseCompare($column, $like_comparator, $relevance * $relevance_multiplier); $cases[] = str_replace( '?', DB::connection()->getPdo()->quote($pre_word . $word . $post_word), $case ); } return implode(' + ', $cases); }

SUKOHI avatar Mar 18 '16 20:03 SUKOHI

@nicolaslopezj plz solve this problem. It is destroying my project.

vtxmg avatar May 30 '16 13:05 vtxmg

thanks @antongorodezkiy.. comment on Feb 24 works for now..

teflondepa avatar Aug 12 '16 17:08 teflondepa

#126 should solve the problem

gufoe avatar Dec 05 '16 17:12 gufoe