add mutators to jsonb columns

pull/26/head
Ondřej Hruška 6 years ago
parent 7746d85e5f
commit df0e06045f
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 6
      app/Http/Controllers/TableController.php
  2. 4
      app/Models/Revision.php
  3. 4
      app/Models/Row.php
  4. 2
      app/Tables/BaseExporter.php
  5. 3
      resources/views/table/_rows.blade.php

@ -44,7 +44,7 @@ class TableController extends Controller
return view('table.view', [
'table' => $tableModel,
'revision' => $revision,
'columns' => Column::columnsFromJson(json_decode($revision->columns)),
'columns' => Column::columnsFromJson($revision->columns),
'rows' => $revision->rows()->paginate(25),
]);
}
@ -204,7 +204,7 @@ class TableController extends Controller
$parsed[$key] = $columns[$i]->cast($val);
}
return [
'data' => json_encode($parsed),
'data' => $parsed,
];
}, $rowTable);
@ -215,7 +215,7 @@ class TableController extends Controller
$revisionFields = [
'note' => "Initial revision of table $u->name/$input->name",
'columns' => json_encode($columns),
'columns' => $columns,
'row_count' => count($rowsData),
];

@ -25,6 +25,10 @@ class Revision extends BaseModel
use HasRelaquentRelationships;
protected $guarded = [];
protected $casts = [
'columns' => 'object',
];
/** Included rows */
public function rows()
{

@ -10,6 +10,10 @@ namespace App\Models;
*/
class Row extends BaseModel
{
protected $casts = [
'data' => 'object',
];
protected $guarded = [];
public $timestamps = false;
}

@ -131,7 +131,7 @@ abstract class BaseExporter
$rows = $revision->rows()->offset($start)->limit($chunkSize)->get();
foreach ($rows as $row) {
$data = json_decode($row->data);
$data = $row->data;
// column renaming, value formatting...

@ -18,9 +18,8 @@
<tbody>
@foreach($rows as $row)
<tr>
@php($rdata = json_decode($row['data'], true))
@foreach($columns as $col)
<td data-id="{{ $row->id }}">{{ $rdata[$col->name] }}</td>
<td data-id="{{ $row->id }}">{{ $row['data']->{$col->name} }}</td>
@endforeach
</tr>
@endforeach

Loading…
Cancel
Save