MicroFrameWork/kernel/IGTabel/ViewJsonTableEloquentModel.php

29 lines
703 B
PHP
Raw Normal View History

2024-07-23 15:22:33 +03:00
<?php
namespace kernel\IGTabel;
use app\helpers\Debug;
use Illuminate\Database\Eloquent\Model;
class ViewJsonTableEloquentModel
{
private string|null $jsonStr;
private array $meta = [];
public function __construct(Model $model, array $params = [])
{
$this->meta['rows'] = $params['rows'] ?? $model->labels();
$this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table;
$this->meta['params'] = $params['params'] ?? [];
$this->meta['actions'] = $params['actions'] ?? [];
$this->jsonStr = (new JSONCreator($this->meta, $model->toArray()))->getJson();
}
public function getJson(): ?string
{
return $this->jsonStr;
}
}