Skip to content
Advertisement

Laravel – query part of a integer and boolean value

In my database I have id column which can contain integer, string, integer + string value. like, check this image:

https://ibb.co/2KNJzVW

As you can see on the id column I have something like this value:

product id
PPAETRABN018283

So, On the input box (my search form) –

If I enter product I can get the result as there is product id value as id.
If I enter PPAE I can get the result as there is PPAETRABN018283 value as id

BUT

If I enter 182 I can’t get any result, although I use LIKE. Can you tell me why?

And

I have another column called availability which contain true and false as boolean. If I do search with true I can get result but I do search with false I can’t get the result. Can you tell me why?

Here is my code:

JavaScript

Advertisement

Answer

In such cases we use LIKE with wrapping %, for example:

JavaScript

And if you search in multiple columns, try:

JavaScript

Note that if where(...) method’s third-parameter is not set, Laravel automatically uses “=” condition-operator in the query by default, while above uses “LIKE” instead.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement