Sunday, May 21, 2017

Collection Where LIKE Laravel 5.4

I know collection doesn't support where LIKE but how can I achieve this.

My data is: enter image description here

collect($products)->where('name', 'LIKE', '%'. $productName . '%');

Laravel doesn't support where like in the collection. I'm thinking to use

collect($products)->filter( function () use ($productName) {

            return preg_match(pattern, subject);
        })

but I don't know how to do it. TY



via Rbex

Advertisement