-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add after and before method for collection
- Loading branch information
Showing
4 changed files
with
83 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# after | ||
|
||
> 获取给定项目之后的项目,如果给定的项目处于最后一个或不存在,则返回 `null`。 | ||
```php | ||
$tasks = collect([ | ||
['id' => 1, 'name' => '设计站点首页'], | ||
['id' => 2, 'name' => '开发站点首页'], | ||
['id' => 3, 'name' => '给首页填充内容'], | ||
['id' => 4, 'name' => '设计站点关于我们页面'], | ||
['id' => 5, 'name' => '开发站点关于我们页面'], | ||
]); | ||
|
||
$tasks->after(fn($task) => $task['name'] === '给首页填充内容'); // ["id" => 4, "name" => "设计站点关于我们页面"] | ||
|
||
$tasks->before(fn (array $task) => $task['name'] === '开发站点关于我们页面'); // null | ||
$tasks->before(fn (array $task) => $task['name'] === 'unknown'); // null | ||
``` | ||
|
||
## 关联方法 | ||
|
||
- [before](before.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# before | ||
|
||
> 获取给定项目之前的项目,如果给定的项目处于第一个或不存在,则返回 `null`。 | ||
```php | ||
$tasks = collect([ | ||
['id' => 1, 'name' => '设计站点首页'], | ||
['id' => 2, 'name' => '开发站点首页'], | ||
['id' => 3, 'name' => '给首页填充内容'], | ||
['id' => 4, 'name' => '设计站点关于我们页面'], | ||
['id' => 5, 'name' => '开发站点关于我们页面'], | ||
]); | ||
|
||
$tasks->before(fn ($task) => $task['name'] === '给首页填充内容'); // ["id" => 2, "name" => "开发站点首页"] | ||
|
||
$tasks->before(fn (array $task) => $task['name'] === '设计站点首页'); // null | ||
$tasks->before(fn (array $task) => $task['name'] === 'unknown'); // null | ||
``` | ||
## 关联方法 | ||
|
||
- [after](after.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters