Top 5 Laravel Bad Practices

  • Bad Practice #1: N+1 query problem, which can cause performance issues. Solution: Use eager loading properly.
  • Bad Practice #2: Loading too much data from the database into memory. Solution: Only load the data that you actually need.
  • Bad Practice #3: Not checking the relationships or objects and chaining in Laravel. Solution: Always check all the objects and handle cases where something does not exist.
  • Bad Practice #4: Returning JSON with 200 status code even when something goes wrong. Solution: Be consistent with your API status code returns, especially 200 versus errors like 400 or 500 codes.
  • Bad Practice #5: Trusting user data without validation. Solution: Always validate the data from your users and never trust them.

via Top 5 Laravel "Bad Practices" (My Opinion)