bessone / searchable

A php trait to search laravel models
MIT License
0 stars 0 forks source link

Global Scope problem #1

Open bessone opened 1 year ago

bessone commented 1 year ago

After upgrading a project to Laravel 9 and PHP 8.1 using search I get the error:

SQLSTATE[HY093]: Invalid parameter number

Debugging the application I understood that the error is caused by a global scope active on the model, where there is a where with two parameters.

It is somehow related to these issues of the original project:

Before upgrading to Laravel 9 and PHP 8.1 (Laravel 8 with PHP 7.4) the problem did not occur.

bessone commented 1 year ago

The error occurs when the two queries are joined, also reporting the parameters which are thus duplicated, but the placeholders are not duplicated

https://github.com/bessone/searchable/blob/b1d24ea45f75e36a11a093efa46fe44c06dd10b7/src/SearchableTrait.php#L354

bessone commented 1 year ago

The pull request https://github.com/bessone/searchable/pull/2 seems to solve the problem, you should test it with various versions of Laravel and/or PHP and also conditions with multiple Global scopes on the model(s) in case of join