Back

Hey Laravel Developers ,

I can't believe I just discovered this feature after working with the framework for over 4 years!

Thanks to @roniestein, I learned that you can pass the column names directly to the get() or all() methods instead of using select() to specify the columns in your queries.

Here's an example code snippet

image

1

236

In response to @aniket

The get() method is really useful, but it might not always be the best choice for your queries.

Here's why:
- The select() method is more flexible. You can chain other query methods easily.
- It's clearer to read, especially for complex queries.
- Using select() allows for better query optimization in some cases.

When to choose between select() and get() methods:
- Use get(['columns']) for quick, simple queries.
- Stick with select() for complex queries or when you need to chain methods.

I just wrote a more detailed article on this www.mirrorlog.com/laravel-query-optimization-choosing-between-select-and-get

161

  • No matching results...
  • Searching...

/ 1000