1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-11 21:14:02 +00:00
This commit is contained in:
Samuel Štancl 2022-04-02 17:18:22 +02:00
parent de8e3941e1
commit 876878c43a
10 changed files with 111 additions and 1 deletions

View file

@ -1,5 +1,5 @@
---
username: alexjgarrett
avatar: 'https://pbs.twimg.com/profile_images/1481608755590615042/Z0usTfe-_normal.jpg'
avatar: 'https://pbs.twimg.com/profile_images/1501500078816739329/xDWzyhtN_normal.jpg'
name: 'Alex Garrett-Smith'
---

View file

@ -0,0 +1,11 @@
---
slug: weekly-thread-2022-13
title: 'Weekly thread #13 of 2022'
tweet_id: '1509994014090711041'
author_username: archtechx
created_at: 2022-04-01T20:40:01+00:00
links: { }
---
🔥 This week's code tips for Laravel developers
A weekly thread 🧵

View file

@ -0,0 +1,11 @@
---
title: 'Understand the difference between `fresh()` and `refresh()`. One returns a *fresh* new instance, while the other *refreshes* an existing instance'
tweet_id: '1509994020109316096'
thread_slug: weekly-thread-2022-13
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FPBT9FCXoAUMen2.jpg'
created_at: 2022-04-01T20:40:03+00:00
slug: 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 models fresh() and refresh() methods? Lets see what each of them do with this little cheatsheet.

View file

@ -0,0 +1,15 @@
---
title: 'You can freeze time in tests'
tweet_id: '1509994017227886594'
thread_slug: weekly-thread-2022-13
author_username: AshAllenDesign
images:
- 'https://pbs.twimg.com/media/FO8k5kAWYAAip2V.jpg'
created_at: 2022-04-01T20:40:02+00:00
slug: you-can-freeze-time-in-tests
---
In your Laravel tests, you might sometimes need to freeze the time.
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

View file

@ -0,0 +1,14 @@
---
title: 'You can now call `newLine()` on Stringable instances'
tweet_id: '1509994032033804290'
thread_slug: weekly-thread-2022-13
author_username: djgeisi
images:
- 'https://pbs.twimg.com/media/FPCdrxkWUAASAm5.jpg'
created_at: 2022-04-01T20:40:06+00:00
slug: you-can-now-call-newline-on-stringable-instances
---
#PHP #Laravel
Since todays Laravel 9.6 release a new newline() method was added to the Stringable Class.
Thanks to @paulandroshchuk who contributed this

View file

@ -0,0 +1,11 @@
---
title: 'You can queue Closures'
tweet_id: '1509994028997169158'
thread_slug: weekly-thread-2022-13
author_username: alexjgarrett
images:
- 'https://pbs.twimg.com/media/FO7OX-ZX0AEQooG.jpg'
created_at: 2022-04-01T20:40:05+00:00
slug: you-can-queue-closures
---
I had no idea you could queue closures in @laravelphp until today.

View file

@ -0,0 +1,11 @@
---
title: 'You can transform variables passed to translation strings right in language files'
tweet_id: '1509994034877534212'
thread_slug: weekly-thread-2022-13
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FPB_HCDXsAUhtvh.jpg'
created_at: 2022-04-01T20:40:06+00:00
slug: 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? 🆙🌍

View file

@ -0,0 +1,11 @@
---
title: 'You can use constrained eager loading to increase performance of database queries that use relations'
tweet_id: '1509994025926885381'
thread_slug: weekly-thread-2022-13
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FOsQc3JXEAgF1P6.jpg'
created_at: 2022-04-01T20:40:04+00:00
slug: you-can-use-constrained-eager-loading-to-increase-performance-of-database-queries-that-use-relations
---
🔥 #Laravel Tip: Eager loading a models 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.

View file

@ -0,0 +1,15 @@
---
title: 'You can use `Notification::assertNothingSentTo()` to check that no notifications were sent to a specific user/notifiable model'
tweet_id: '1509994037830332416'
thread_slug: weekly-thread-2022-13
author_username: AshAllenDesign
images:
- 'https://pbs.twimg.com/media/FO8nW9TXsBExZTp.jpg'
created_at: 2022-04-01T20:40:07+00:00
slug: you-can-use-notificationassertnothingsentto-to-check-that-no-notifications-were-sent-to-a-specific-usernotifiable-model
---
🚀 You can now use the new "assertNothingSentTo" method in your Laravel tests.
You can use this to ensure that no notifications were sent to a given notifiable model (or models)!
#laravel #php

View file

@ -0,0 +1,11 @@
---
title: 'You can use use `whereBetween` to filter for records between two timestamps'
tweet_id: '1509994023083147264'
thread_slug: weekly-thread-2022-13
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FO8rgMGXsAkX0SD.jpg'
created_at: 2022-04-01T20:40:04+00:00
slug: 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 ❔❔