Skip to content

Commit 1fa6cb0

Browse files
committed
added tip #343
1 parent 0428b40 commit 1fa6cb0

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
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) (62 tips)
13+
- 🛠️ [Helpers Tips](./tips/helpers.md) (63 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)

stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"totalTips": 342}
1+
{"totalTips": 343}

tips/helpers.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- [Check If a String Is a URL](#laravel-tip--check-if-a-string-is-a-url-️)
6363
- [Extract Text Between Strings](#laravel-tip--extract-text-between-strings-️)
6464
- [Reusable Pipelines](#laravel-tip--reusable-pipelines-️)
65+
- [Clamp Numbers](#laravel-tip--clamp-numbers-️)
6566

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

@@ -1140,3 +1141,19 @@ Route::get('/upload-image', function (Hub $hub, Request $request) {
11401141
$processedImage = $hub->pipe($image, 'process-uploaded-image');
11411142
});
11421143
```
1144+
1145+
## Laravel Tip 💡: Clamp Numbers ([⬆️](#helpers-tips-cd-))
1146+
1147+
Have you ever needed to keep a number within a specific range, like a rating or a computed value? While you can hack your way through with min and max, Laravel ships with an elegant helper "clamp" to do exactly that 🚀
1148+
1149+
```php
1150+
<?php
1151+
1152+
use Illuminate\Support\Number;
1153+
1154+
Number::clamp(55, min: 10, max: 50); // Above the range, so the max 50 is returned
1155+
1156+
Number::clamp(5, min: 10, max: 50); // Below the range, so the min 10 is returned
1157+
1158+
Number::clamp(20, min: 10, max: 50); // Within the range, so the original value 20 is returned
1159+
```

0 commit comments

Comments
 (0)