This is demo code to show whereRaw optional array handling error
This project uses PostgreSQL and PGroonga. Please install both to continue.
If you are using macOS, you can install PGroonga with brew.
% brew install pgroonga
Install and Reproduce the error
Clone this repo and do following.
% createdb whereraw_laravel
% cp -p .env.example .env
% composer install
% php artisan key:generate
% php artisan migrate --seed
% php artisan serve
Demo
Access http://127.0.0.1:8000
Click "Without Optional" -> Works fine.
Click "With Optional" -> SQLSTATE[08P01]: <>.
Got 2 solutions for this
I got 2 solutions. One from PGroonga Collaborator and other from Laravel Community.
PGroonga Way
I got this solution via Twitter.
$query->whereRaw('jsonbdata &` (\'(paths @ "title" || paths @ "body") && query("string", \' || pgroonga_escape(?) || \')\')', ["cat alice"]);
Check out this branch.
Laravel/PHP Way
I got this solution from Laravel issue report which I posted.
$input = 'cat alice';
$query->whereRaw('jsonbdata &` ?', [
'(paths @ "title" || paths @ "body") && query("string", "'. addslashes($input) .'")'
]);
Check out this branch.