Skip to content

Instantly share code, notes, and snippets.

@thiagomarini
Created December 6, 2018 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomarini/3dd27b583c37e8ac93358afe55adb565 to your computer and use it in GitHub Desktop.
Save thiagomarini/3dd27b583c37e8ac93358afe55adb565 to your computer and use it in GitHub Desktop.
Data Fetcher Example
<?php
namespace Weengs\DataFetcher\Collections\Admin;
use Weengs\DataFetcher\DataFetcherInterface;
use Weengs\Models\WmsUser\App;
class ListApps implements DataFetcherInterface
{
/**
* @param array $params
* @return array
*/
public function fetch(array $params): array
{
$apps = App::orderBy('name')->get();
return [
'apps' => $apps->map(function (App $app) {
return [
'id' => $app->id,
'name' => $app->name,
'description' => $app->description,
'created_at' => $app->created_at->format('d M Y H:i'),
'updated_at' => $app->updated_at->format('d M Y H:i'),
];
})
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment