mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 13:24:03 +00:00
13/2022
This commit is contained in:
parent
de8e3941e1
commit
876878c43a
10 changed files with 111 additions and 1 deletions
|
|
@ -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 model’s ‘fresh()’ and ‘refresh()’ methods? Let’s see what each of them do with this little cheatsheet.
|
||||
15
content/tips/you-can-freeze-time-in-tests.md
Normal file
15
content/tips/you-can-freeze-time-in-tests.md
Normal 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
|
||||
|
|
@ -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
|
||||
11
content/tips/you-can-queue-closures.md
Normal file
11
content/tips/you-can-queue-closures.md
Normal 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.
|
||||
|
|
@ -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? 🆙🌍
|
||||
|
|
@ -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 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.
|
||||
|
|
@ -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
|
||||
|
|
@ -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 ❔❔
|
||||
Loading…
Add table
Add a link
Reference in a new issue