# Collection
Lodata can expose any object that implements the Laravel Enumerable (opens new window) contract, including Collection (opens new window) and LazyCollection (opens new window). Lodata supports both numeric and string keyed collections.
Any array of data can be easily converted to a Collection using the
collect()
(opens new window) method.
class LodataServiceProvider extends ServiceProvider
{
public function boot()
{
$entityType = new \Flat3\Lodata\EntityType('example');
$entityType->setKey(new \Flat3\Lodata\DeclaredProperty('id', \Flat3\Lodata\Type::string()));
$entityType->addDeclaredProperty('name', \Flat3\Lodata\Type::string());
$entityType->addDeclaredProperty('dob', \Flat3\Lodata\Type::date());
$entitySet = new \Flat3\Lodata\Drivers\CollectionEntitySet('examples', $entityType);
$entitySet->setCollection($collection);
\Lodata::add($entitySet);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
First define an empty entity type with the name example
, and configure the key property as either numeric (eg Edm.Int64
)
or string (Edm.String
).
Then add the declared properties used in the collection values to complete the type.
Finally, create the CollectionEntitySet
using the entity type, and call setCollection()
to connect your collection.
There is a PHP implementation for almost all the available $filter
expressions and functions.