πŸ”₯ Weekly thread #45 of 2021

πŸ”₯ This week's tips for Laravel developers

As always, huge thanks to everyone making these tweets ❀️

Use Common Table Expressions to refine your data in complex Eloquent queries

8

πŸ”₯ Use Common Table Expressions to refine your data in complex Eloquent queries

Use Common Table Expressions to refine your data in complex Eloquent queries

⚑️ Database Tip

Sometimes you have very complex queries involving multiple calculation steps. Instead of nesting queries or doing it in application code you can use Common Table Expressions (CTE) to refine your data in every step and even reuse former steps.

Use the --requests flag when creating models to also create form requests

6

πŸ”₯ Use the --requests flag when creating models to also create form requests

Use the --requests flag when creating models to also create form requests

This release of Laravel also includes a "--requests" flag when making models via Artisan. This option will create a "Store{Model}Request" and "Update{Model}Request" form request + update the controller to use those requests on their respective methods. πŸ”₯

Thanks @PovilasKorop!

Use the Str::headline() method to convert strings to studly words

3

πŸ”₯ Use the Str::headline() method to convert strings to studly words

Use the Str::headline() method to convert strings to studly words

πŸ’‘It's refactor time!

Laravel 8.65 introduces the Str::headline() method, this method converts a string into studly words!

A small change like this results in less noise in my code.

Thanks @SteveTheBauman for this implementation! πŸ™Œ

Use the withAggregate() method to add related values to Eloquent queries using subselects

1

πŸ”₯ Use the withAggregate() method to add related values to Eloquent queries using subselects

Use the withAggregate() method to add related values to Eloquent queries using subselects

πŸ’‘ A little #Laravel tip from the latest blog post to get the week started!

Under the hood, the withAvg/withCount/withSum and other methods in Eloquent use the 'withAggregate' method. You can use this method to add a subselect based on a relationship πŸ’«

#PHP #webdev #OpenSource

We're writing a book, you can get it for free here.