9
π₯ Add a recursive() macro to convert an array including its children to Collections
A handy @laravelphp Collection macro to convert an array and its children to Collections, using recursion.
π₯ This week's tips for Laravel developers
As always, huge thanks to everyone making these tweets β€οΈ
9
A handy @laravelphp Collection macro to convert an array and its children to Collections, using recursion.
8
β‘οΈ 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.
7
#Laravel Tip:
If you are running Laravel v8.70
, you can chain can()
method directly instead of middleware('can:..')
Here is and example:
6
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!
5
I really love using Laravel's Eloquent factories for generating fake test data. Did you know that you can also use them to generate fake API response data by using "Fluent" as the model name? Super cool! π€―
4
π‘ Check if there's a previous URL when showing error pages instead of linking to static page!
It's incredibly useful if your marketing and app pages share the same error pages! It makes sure your users won't get lost :)
3
π‘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! π
2
Happy Monday π Let's start the week with a Laravel tip: You can use the Prunable trait to automatically remove models from your database. For example, you can permanently remove soft deleted models after a few days.
1
π‘ 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. We're writing a book! Join the early access to get it for free.