Skip to main content
Code Review

Return to Answer

replaced http://ux.stackexchange.com/ with https://ux.stackexchange.com/
Source Link

Here are few things I'd do to improve your code:

  • I would compact your first if statement into something such as if (Categories::where('name', 'LIKE', '%'. $search .'%')->first()) { since you only use $result for that purpose.

  • Remove that unnecessary horizontal space after your first assignment to $categories.

  • I hope that your flash messages are only for development purposes. They aren't very useful or user friendly as they are right now. Look at studied websites (Amazon, StackExchange, etc.) and UX.SE UX.SE for tips on how to improve the user experience of your search function.

  • Be careful using the compact function. It's easy to lose track of it and forget to update it or your variables and therefore have something throw an error later on.

  • Fix the format of your else. Pick-and-choose either

     } else { 
    

    or

     }
     else
     {
    
  • Most search functions don't return anything when nothing was found. Again, this an issue to bring up at UX.SE, but your user might find themselves thinking that the results from your else clause are actually what they're looking for.

Overall, very nice. I'm sure you've done this, if not though, read through what you find from a search like this just to see how others have solved this problem. You'll find out good ways and bad ways of doing what you've done.

Here are few things I'd do to improve your code:

  • I would compact your first if statement into something such as if (Categories::where('name', 'LIKE', '%'. $search .'%')->first()) { since you only use $result for that purpose.

  • Remove that unnecessary horizontal space after your first assignment to $categories.

  • I hope that your flash messages are only for development purposes. They aren't very useful or user friendly as they are right now. Look at studied websites (Amazon, StackExchange, etc.) and UX.SE for tips on how to improve the user experience of your search function.

  • Be careful using the compact function. It's easy to lose track of it and forget to update it or your variables and therefore have something throw an error later on.

  • Fix the format of your else. Pick-and-choose either

     } else { 
    

    or

     }
     else
     {
    
  • Most search functions don't return anything when nothing was found. Again, this an issue to bring up at UX.SE, but your user might find themselves thinking that the results from your else clause are actually what they're looking for.

Overall, very nice. I'm sure you've done this, if not though, read through what you find from a search like this just to see how others have solved this problem. You'll find out good ways and bad ways of doing what you've done.

Here are few things I'd do to improve your code:

  • I would compact your first if statement into something such as if (Categories::where('name', 'LIKE', '%'. $search .'%')->first()) { since you only use $result for that purpose.

  • Remove that unnecessary horizontal space after your first assignment to $categories.

  • I hope that your flash messages are only for development purposes. They aren't very useful or user friendly as they are right now. Look at studied websites (Amazon, StackExchange, etc.) and UX.SE for tips on how to improve the user experience of your search function.

  • Be careful using the compact function. It's easy to lose track of it and forget to update it or your variables and therefore have something throw an error later on.

  • Fix the format of your else. Pick-and-choose either

     } else { 
    

    or

     }
     else
     {
    
  • Most search functions don't return anything when nothing was found. Again, this an issue to bring up at UX.SE, but your user might find themselves thinking that the results from your else clause are actually what they're looking for.

Overall, very nice. I'm sure you've done this, if not though, read through what you find from a search like this just to see how others have solved this problem. You'll find out good ways and bad ways of doing what you've done.

Source Link
Alex L
  • 5.8k
  • 2
  • 26
  • 69

Here are few things I'd do to improve your code:

  • I would compact your first if statement into something such as if (Categories::where('name', 'LIKE', '%'. $search .'%')->first()) { since you only use $result for that purpose.

  • Remove that unnecessary horizontal space after your first assignment to $categories.

  • I hope that your flash messages are only for development purposes. They aren't very useful or user friendly as they are right now. Look at studied websites (Amazon, StackExchange, etc.) and UX.SE for tips on how to improve the user experience of your search function.

  • Be careful using the compact function. It's easy to lose track of it and forget to update it or your variables and therefore have something throw an error later on.

  • Fix the format of your else. Pick-and-choose either

     } else { 
    

    or

     }
     else
     {
    
  • Most search functions don't return anything when nothing was found. Again, this an issue to bring up at UX.SE, but your user might find themselves thinking that the results from your else clause are actually what they're looking for.

Overall, very nice. I'm sure you've done this, if not though, read through what you find from a search like this just to see how others have solved this problem. You'll find out good ways and bad ways of doing what you've done.

lang-php

AltStyle によって変換されたページ (->オリジナル) /