[WIP] Setup of skeleton
This commit is contained in:
50
app/Repositories/Core/Database.php
Normal file
50
app/Repositories/Core/Database.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Collective\Html\Eloquent\FormAccessible;
|
||||
|
||||
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]]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user