Skip to main content
14 events
when toggle format what by license comment
Feb 9, 2022 at 21:25 history edited Laurel CC BY-SA 4.0
added 16 characters in body
Feb 3, 2022 at 19:40 comment added Laurel @HashimAziz You can use str_replace in PHP to remove characters from a string. The MATCH solution looks fine (as long as you make sure to format it like that, in a way that prevents SQL injection), but I really wonder if implementing the first section of my answer would solve most of your performance problems without it. I have a search function in my website where a user can search "john bob" and it matches with LIKE across first and last name columns (returning "Johnathan Bob" and "Roboberty O'Johnson") and it doesn't have any performance issues w/ 500+ people in the db.
Feb 3, 2022 at 19:26 comment added Hashim Aziz Also what do you think about the approach of using match instead of like? Is it possible/worth implementing in my case?
Feb 3, 2022 at 19:25 comment added Hashim Aziz Ah, so basically the SQL wildcard. How would this stripping be done? I did a quick search but it didn't seem to bring up anything relevant.
Feb 3, 2022 at 19:20 comment added Laurel @HashimAziz I also clarified that part about percents. If you want to see what the problem is with it, have the user search for something like b%t, which would match "boot" and "boat". Similarly, if they searched for _ that would match everything.
Feb 3, 2022 at 19:14 history edited Laurel CC BY-SA 4.0
added 162 characters in body
Feb 3, 2022 at 19:10 comment added Hashim Aziz I now see what you're saying about collect() and have implemented accordingly. However, my SQL queries simply don't work without wrapping them in %.
Feb 3, 2022 at 18:57 history edited Laurel CC BY-SA 4.0
added 54 characters in body
Feb 3, 2022 at 18:57 comment added Hashim Aziz Interestingly I was under the impression that is required when using LIKE in SQL. If not, what does it add and why is it so commonly used? Also regarding the loading of images, all the slugs are generated by me, but is this a typical way to load images/assets? It seems there should be a more idiomatic Laravel way of doing this that doesn't hardcode paths, but maybe this is the more common way to do it.
Feb 3, 2022 at 18:44 vote accept Hashim Aziz
Feb 3, 2022 at 18:37 comment added Hashim Aziz Similarly with collect()->add($search_term) - it's to force the search result (which is often an object of one, but not always) into a Collection. By doing this the search conditions always return Collections that can then easily be output in Blade without additional logic. Maybe I went about this the wrong way and it's worth making the Blade file a little less clean for the sake of returning only the results I need. Although it's worth nothing that only two of the conditions always return just one result so for the other two a get() will always be needed.
Feb 3, 2022 at 18:30 comment added Hashim Aziz Some great tips here and much less radical than I thought it would be - I assumed that my general approach of using if loops would be bad. RE: the for loops - the first two are to isolate the slug into a variable for the purpose of the return view(), and the third one was to make every searchterm return a manufacturer, which would allow me to just do $result->slug on the view for all of the search results. Essentially to prevent as much conditional checking in the view as possible, in hindsight maybe laziness/optimising the wrong side.
Feb 2, 2022 at 23:21 history edited Laurel CC BY-SA 4.0
added 1 character in body
Feb 2, 2022 at 22:17 history answered Laurel CC BY-SA 4.0