Skip to content

Commit baa697a

Browse files
Update README.md
1 parent c5062fc commit baa697a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
# PHP dataloader
2-
Quick and dirty port of the [Facebook's DataLoader](https://github.com/facebook/dataloader) to PHP
2+
Quick port of the [Facebook's DataLoader](https://github.com/facebook/dataloader) to PHP. Async superpowers from [ReactPHP](https://github.com/reactphp)
33

44
## Todo
55
- [x] Primary API
66
- [x] Error / rejected promise handling
77
- [x] Options support
88
- [x] Abuse tests and meaningful exceptions
9-
- [ ] Documentation for the API
9+
- [ ] Documentation for the API and usage examples
1010
- [ ] Abstract event loop and promises to be usable with any implementation?
11+
12+
## Usage with common ORM's
13+
14+
### Eloquent (Laravel)
15+
16+
```php
17+
$userByIdLoader = new DataLoader(function ($ids) {
18+
$users = User::findMany($ids);
19+
20+
// Make sure that the users are on the same order as the given ids
21+
$orderedUsers = collect($ids)->map(function ($id) use ($users) {
22+
foreach ($users as $user) {
23+
if ($user->id === $id) {
24+
return $user;
25+
}
26+
});
27+
28+
return \React\Promise\resolve($orderedUsers);
29+
}, $eventLoopFromIoCContainer, $cacheMapFromIoCContainer);
30+
```
31+
32+

0 commit comments

Comments
 (0)