Skip to content

Commit 390c782

Browse files
committed
added tip #345
1 parent fec6195 commit 390c782

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Daily Laravel/PHP tips I share on my [X](https://x.com/OussamaMater) and [Linked
1010
Currently, there are over 300 tips categorized as follows:
1111

1212
- 🗄️ [Eloquent & Database Tips](./tips/eloquent-and-database.md) (95 tips)
13-
- 🛠️ [Helpers Tips](./tips/helpers.md) (64 tips)
13+
- 🛠️ [Helpers Tips](./tips/helpers.md) (65 tips)
1414
- 🧪 [Testing Tips](./tips/testing.md) (28 tips)
1515
- 💻 [Artisan & Console Command Tips](./tips/console.md) (26 tips)
1616
- 🔄 [Routing & Request Tips](./tips/routing.md) (22 tips)

tips/helpers.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- [Extract Text Between Strings](#laravel-tip--extract-text-between-strings-️)
6464
- [Reusable Pipelines](#laravel-tip--reusable-pipelines-️)
6565
- [Clamp Numbers](#laravel-tip--clamp-numbers-️)
66+
- [Date Checks with Carbon](#laravel-tip--date-checks-with-carbon-️)
6667

6768
## Laravel Tip 💡: The "squish" method ([⬆️](#helpers-tips-cd-))
6869

@@ -1183,3 +1184,36 @@ Product::all()->select('name', 'price');
11831184
* - only() can't handle nested arrays
11841185
*/
11851186
```
1187+
1188+
## Laravel Tip 💡: Date Checks with Carbon ([⬆️](#helpers-tips-cd-))
1189+
1190+
I know you've had to check if a date has expired or is in the future at least once. Since Laravel uses Carbon under the hood, you've got access to a ton of helpers to handle all that elegantly 🚀
1191+
1192+
```php
1193+
<?php
1194+
1195+
use Illuminate\Support\Carbon;
1196+
1197+
$date = Carbon::createFromDate(2025, 7, 28);
1198+
1199+
$date->isToday(); // true
1200+
$date->isTomorrow(); // false
1201+
$date->isYesterday(); // false
1202+
1203+
$date->isWeekday(); // true
1204+
$date->isWeekend(); // false
1205+
1206+
$date->isFuture(); // false
1207+
$date->isPast(); // false
1208+
1209+
// But wait, there's more 🔥
1210+
$date->isSameDay(now()); // true
1211+
$date->isSameWeek(now()); // true
1212+
$date->isSameMonth(now()); // true
1213+
$date->isSameYear(now()); // true
1214+
1215+
// You can even specify a unit
1216+
$date->isSameUnit('year', now()); // true
1217+
1218+
// And the list goes on... 😎
1219+
```

0 commit comments

Comments
 (0)