PHP code example of label305 / dug
1. Go to this page and download the library: Download label305/dug library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
label305 / dug example snippets
$source = Source::build(['users', '/[0-9]+/'], function($path) {
$users = User::whereIn('id', $path[1])->get();
$result = [];
foreach($users as $user) {
$result[] = Data::build(
['users', $user->getId()],
[
'id' => $user->getId(),
'name' => $user->getName()
]
);
}
return $result;
});
$source = Source::build(['users', '/[0-9]+/'], function($path) {
$users = User::whereIn('id', $path[1])->get();
$result = [];
foreach($users as $user) {
$result[] = Data::build(
['users', $user->getId()],
[
'id' => $user->getId(),
'name' => $user->getName()
]
);
}
$unreadCounts = Counters::whereIn('user_id', $path[1])->get();
foreach($unreadCounts as $unreadCount) {
$result[] = Data::build(
['users', $unreadCount->getUserId()],
[
'unread_count' => $unreadCount->getValue()
]
);
}
return $result;
});
$source = Source::build(['users', '/[0-9]+/'], function($path) {
$users = User::whereIn('id', $path[1])->get();
$result = [];
foreach($users as $user) {
$result[] = Data::build(
['users', $user->getId()],
[
'id' => $user->getId(),
'name' => $user->getName(),
'company' => new ReferenceToSingle(['companies', $user->getCompany()])
]
}
return $result;
});
class UserProvider implements DataProvider {
public function handle(array $path):array
//Your magic
}
}