50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
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("rank")
|
|
->get()
|
|
->map(FieldModule::fromDb(...))
|
|
->toArray();
|
|
}
|
|
|
|
public static function findOne(string $id): ?Field
|
|
{
|
|
return DB::table(self::TABLE_NAME)
|
|
->where("id", $id)
|
|
->get()
|
|
->map(FieldModule::fromDb(...))
|
|
->first();
|
|
}
|
|
|
|
public static function insert(Field $field): void
|
|
{
|
|
DB::table(self::TABLE_NAME)->insert(FieldModule::toDb($field));
|
|
}
|
|
|
|
public static function update(Field $field): void
|
|
{
|
|
DB::table(self::TABLE_NAME)
|
|
->where("id", $field->id)
|
|
->update(FieldModule::toDb($field));
|
|
}
|
|
|
|
public static function delete(string $fieldId): void
|
|
{
|
|
DB::table(self::TABLE_NAME)->where("id", $fieldId)->delete();
|
|
}
|
|
}
|