You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: helpers.md
+41-15Lines changed: 41 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
170
170
[validator](#method-validator)
171
171
[value](#method-value)
172
172
[view](#method-view)
173
+
[with](#method-with)
173
174
174
175
</div>
175
176
@@ -709,7 +710,7 @@ The `camel_case` function converts the given string to `camelCase`:
709
710
<aname="method-class-basename"></a>
710
711
#### `class_basename()` {#collection-method}
711
712
712
-
-The `class_basename` returns the class name of the given class with the class' namespace removed:
713
+
The `class_basename` returns the class name of the given class with the class' namespace removed:
713
714
714
715
$class = class_basename('Foo\Bar\Baz');
715
716
@@ -833,7 +834,7 @@ The `str_is` function determines if a given string matches a given pattern. Aste
833
834
<aname="method-str-limit"></a>
834
835
#### `str_limit()` {#collection-method}
835
836
836
-
The `str_limit` function limits the number of characters in a string. The function accepts a string as its first argument and the maximum number of resulting characters as its second argument:
837
+
The `str_limit` function truncates the given string at the specified length:
837
838
838
839
$truncated = str_limit('The quick brown fox jumps over the lazy dog', 20);
839
840
@@ -1159,7 +1160,7 @@ You may add items to the cache by passing an array of key / value pairs to the f
The `transform` function executes a Closure on a given value if the value is not [blank](#method-blank) and returns the result of the Closure:
1520
+
The `transform` function executes a `Closure` on a given value if the value is not [blank](#method-blank) and returns the result of the `Closure`:
1520
1521
1521
-
transform(5, function ($value) {
1522
+
$callback = function ($value) {
1522
1523
return $value * 2;
1523
-
});
1524
+
};
1525
+
1526
+
$result = transform(5, $callback);
1524
1527
1525
1528
// 10
1526
1529
1527
-
A default value or Closure may also be passed as the third parameter to the method. This value will be returned if the given value is blank:
1530
+
A default value or `Closure` may also be passed as the third parameter to the method. This value will be returned if the given value is blank:
1528
1531
1529
-
transform(null, function ($value) {
1530
-
return $value * 2;
1531
-
}, 'The value is blank');
1532
+
$result = transform(null, $callback, 'The value is blank');
1532
1533
1533
1534
// The value is blank
1534
1535
@@ -1542,17 +1543,42 @@ The `validator` function creates a new [validator](/docs/{{version}}/validation)
1542
1543
<aname="method-value"></a>
1543
1544
#### `value()` {#collection-method}
1544
1545
1545
-
The `value` function's behavior will simply return the value it is given. However, if you pass a `Closure` to the function, the `Closure` will be executed then its result will be returned:
1546
+
The `value` function returns the value it is given. However, if you pass a `Closure` to the function, the `Closure` will be executed then its result will be returned:
1546
1547
1547
-
$value = value(function () {
1548
-
return 'bar';
1548
+
$result = value(true);
1549
+
1550
+
// true
1551
+
1552
+
$result = value(function () {
1553
+
return false;
1549
1554
});
1550
1555
1551
-
// bar
1556
+
// false
1552
1557
1553
1558
<aname="method-view"></a>
1554
1559
#### `view()` {#collection-method}
1555
1560
1556
1561
The `view` function retrieves a [view](/docs/{{version}}/views) instance:
1557
1562
1558
1563
return view('auth.login');
1564
+
1565
+
<aname="method-with"></a>
1566
+
#### `with()` {#collection-method}
1567
+
1568
+
The `with` function returns the value it is given. However, if you also pass a `Closure` as a second argument to the function, the `Closure` will be executed then its result will be returned:
0 commit comments