add Eloquent Tables
This commit is contained in:
@ -1,37 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\IGTabel;
|
||||
|
||||
use app\helpers\Debug;
|
||||
use app\models\User;
|
||||
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();
|
||||
$model = $model->toArray();
|
||||
if(isset($model['user_id']))
|
||||
{
|
||||
$model['user_id'] = User::find($model['user_id'])->username;
|
||||
}
|
||||
|
||||
$this->jsonStr = (new JSONCreator($this->meta, $model))->getJson();
|
||||
}
|
||||
|
||||
public function getJson(): ?string
|
||||
{
|
||||
return $this->jsonStr;
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
//namespace kernel\IGTabel;
|
||||
//
|
||||
//use app\helpers\Debug;
|
||||
//use app\models\User;
|
||||
//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();
|
||||
// $model = $model->toArray();
|
||||
// if(isset($model['user_id']))
|
||||
// {
|
||||
// $model['user_id'] = User::find($model['user_id'])->username;
|
||||
// }
|
||||
//
|
||||
// $this->jsonStr = (new JSONCreator($this->meta, $model))->getJson();
|
||||
// }
|
||||
//
|
||||
// public function getJson(): ?string
|
||||
// {
|
||||
// return $this->jsonStr;
|
||||
// }
|
||||
//
|
||||
//}
|
Reference in New Issue
Block a user