29 lines
633 B
PHP
29 lines
633 B
PHP
|
|
<?php namespace Lucent\Core\Repository;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Lucent\Core\Schema\Data\Field;
|
||
|
|
use Lucent\Core\Schema\FieldModule;
|
||
|
|
use Lucent\Core\Schema\SchemaModule;
|
||
|
|
|
||
|
|
class FieldRepo
|
||
|
|
{
|
||
|
|
const TABLE_NAME = "fields";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @@return Field[]
|
||
|
|
*/
|
||
|
|
public static function all(): array
|
||
|
|
{
|
||
|
|
return DB::table(self::TABLE_NAME)
|
||
|
|
->orderBy("name")
|
||
|
|
->get()
|
||
|
|
->map(SchemaModule::fromDb(...))
|
||
|
|
->toArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function insert(Field $field): void
|
||
|
|
{
|
||
|
|
DB::table(self::TABLE_NAME)->insert(FieldModule::toDb($field));
|
||
|
|
}
|
||
|
|
}
|