
? This week's code tips for Laravel developers A weekly thread ?
? You can freeze time in tests
❄️In your Laravel tests, you might sometimes need to freeze the time.
— Ash Allen ? (@AshAllenDesign) March 30, 2022
This is particularly useful if you're trying to make assertions based on timestamps or need to make queries based on dates and/or times.#laravel #php pic.twitter.com/4tDu0zUrMB
? Understand the difference between `fresh()` and `refresh()`. One returns a *fresh* new instance, while the other *refreshes* an existing instance
? #Laravel Tip: Ever wondered what the differences are between an Eloquent model’s ‘fresh()’ and ‘refresh()’ methods? Let’s see what each of them do with this little cheatsheet. pic.twitter.com/keIDnNHlP1
— Matt Kingshott ? (@mattkingshott) March 29, 2022
? You can use use `whereBetween` to filter for records between two timestamps
How to retrieve records between two timestamps in Laravel ? Use whereBetween with a from and to date. If you need to provide fallback you can do so with the nullish coalescing operator ❔❔ pic.twitter.com/oLkjVtduLy
— Daniel Eckermann (@ecrmnn) March 28, 2022
? You can use constrained eager loading to increase performance of database queries that use relations
? #Laravel Tip: Eager loading a model’s relationships is a great way to improve performance / avoid the N+1 problem. However, you can go further… with constrained eager loading you can tell Laravel to only load the related records you actually need. pic.twitter.com/Rq45SqfeNS
— Matt Kingshott ? (@mattkingshott) March 25, 2022
? You can queue Closures
I had no idea you could queue closures in @laravelphp until today. pic.twitter.com/ByjR3TIw35
— Alex Garrett-Smith (@alexjgarrett) March 28, 2022
? You can now call `newLine()` on Stringable instances
#PHP #Laravel
— Tim Geisendoerfer (@djgeisi) March 29, 2022
Since todays Laravel 9.6 release a new newline() method was added to the Stringable Class.
Thanks to @paulandroshchuk who contributed this pic.twitter.com/JGfdmB8g8W
? You can transform variables passed to translation strings right in language files
Did you know that translation variables can easily be capitalized or converterd to lowercase and uppcase in Laravel? ?? pic.twitter.com/MKIuwEE6Wm
— Daniel Eckermann (@ecrmnn) March 29, 2022
? You can use `Notification::assertNothingSentTo()` to check that no notifications were sent to a specific user/notifiable model
? You can now use the new "assertNothingSentTo" method in your Laravel tests.
— Ash Allen ? (@AshAllenDesign) March 31, 2022
You can use this to ensure that no notifications were sent to a given notifiable model (or models)!#laravel #php pic.twitter.com/BYGZmsPdmm
? Bonus 1: `Carbon` cheat sheet for generating dates
? #Laravel + Carbon makes it easy to get date bounds for week/month/year periods. pic.twitter.com/jTvtKRMzhj
— Placebo Domingo (@brbcoding) March 29, 2022
? Bonus 2: Artisan `make:model` cheat sheet
Laravel tip of the day: here's how many additional flags you can use to generate the model with something extra on top.
— Povilas Korop | Laravel Youtuber & Content Creator (@PovilasKorop) March 31, 2022
You can also see the full list by running
php artisan make:model --help pic.twitter.com/vF26wg5BEV
? Last week's thread if want to read more tips ?
? This week's code tips for Laravel developers
— ARCHTECH (@archtechx) March 25, 2022
A weekly thread ?
Follow us on Twitter
to be informed of the latest developments and updates!
Follow @tivitikothreadYou can easily use to @tivitikothread bot for create more readable thread!