Files
opensem/app/Repositories/Core/Database.php
2021-11-01 16:26:31 +01:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Repositories\Core;
use Illuminate\Support\Facades\Schema;
use Collective\Html\Eloquent\Form;
class Database
{
public static function getForm($model)
{
$form = '';
$data = self::getTableFields($model);
foreach ($data as $item) {
switch ($item['type']) {
case 'integer':
$form .= Form::number($item['name']);
break;
case 'string':
$form .= Form::number($item['name']);
break;
case 'date':
$form .= Form::date($item['name']);
break;
case 'boolean':
$form .= Form::checkbox($item['name']);
break;
}
}
return $form;
}
public static function getTableFields($model)
{
$table = new $model();
$data = [];
// get the column names for the table
$columns = Schema::getColumnListing($table->getTable());
foreach ($columns as &$column) {
$type = Schema::getColumnType($table->getTable(), $column);
array_push($data, ['name' => $column, 'type' => $type]);
}
return $data;
}
public static function getPopulate($model, $route, $id)
{
echo Form::model($model, ['route' => [$route.'.update', $id]]);
}
}