-3

I am saving multiple categories of single product in database using serialize. but now I need a search option on base of name and categories. Name works fine, but I was unable to figure out how can I use eloquent for category search.

Here is example:

Product 1 belong to A, B, C, D categories. In search user checked B, C. So I need to show product 1 under B and C selection (both are array).

For now, I use whereIn() but it only work if we have single id in database and array is coming from form. In my case I have array in db as well as in form. Any suggestion?

  • 1
    show us what you tried so far – Abdulla Nilam Apr 26 '23 at 07:04
  • You can use [FIND_IN_SET](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set) but you should read - [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – user1191247 Apr 26 '23 at 07:31
  • You should take a look at [how do I ask a good question](https://stackoverflow.com/help/how-to-ask). You should show us what you've tried and provide a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) to help us figure out what the problem is. – geertjanknapen Apr 26 '23 at 07:47

1 Answers1

-1

You can use package laravel cross eloquent search to search data across multiple models.

https://github.com/protonemedia/laravel-cross-eloquent-search

In your case, I think you are looking for something to search array [A,B] from database array column [A,B,C,D,E]. You should check this.

https://laravel.com/docs/10.x/queries#json-where-clauses

Zafeer Ahmad
  • 240
  • 5
  • 17