Skip to content

Commit 8854cb5

Browse files
committed
Merge remote-tracking branch 'yajra/9.0' into 9.0
2 parents fb6b6c1 + 62f14b2 commit 8854cb5

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
### [Unreleased]
1010

11+
### [v9.3.0] - 2019-05-21
12+
13+
- Prevent malformed UTF-8 characters in debug mode. [#2088], credits to [@drsdre].
14+
- Add the possibility to makeHidden() some attribute of a model. [#2085], credits to [@Arkhas].
15+
1116
### [v9.2.0] - 2019-05-09
1217

1318
- Enable the dotted notation in the ->removeColumn() function. [#2082], credits to [@Arkhas].
@@ -319,7 +324,8 @@ return (new CollectionDataTable(User::all())->toJson();
319324
- Fix orderColumn api where related tables are not joined.
320325
- Fix nested with relation search and sort function.
321326

322-
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.2.0...9.0
327+
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.3.0...9.0
328+
[v9.3.0]: https://github.com/yajra/laravel-datatables/compare/v9.2.0...v9.3.0
323329
[v9.2.0]: https://github.com/yajra/laravel-datatables/compare/v9.1.1...v9.2.0
324330
[v9.1.1]: https://github.com/yajra/laravel-datatables/compare/v9.1.0...v9.1.1
325331
[v9.1.0]: https://github.com/yajra/laravel-datatables/compare/v9.0.1...v9.1.0
@@ -427,6 +433,8 @@ return (new CollectionDataTable(User::all())->toJson();
427433
[#2082]: https://github.com/yajra/laravel-datatables/pull/2082
428434
[#2079]: https://github.com/yajra/laravel-datatables/pull/2079
429435
[#2083]: https://github.com/yajra/laravel-datatables/pull/2083
436+
[#2088]: https://github.com/yajra/laravel-datatables/pull/2088
437+
[#2085]: https://github.com/yajra/laravel-datatables/pull/2085
430438

431439
[#2058]: https://github.com/yajra/laravel-datatables/issues/2058
432440
[#1626]: https://github.com/yajra/laravel-datatables/issues/1626
@@ -490,3 +498,4 @@ return (new CollectionDataTable(User::all())->toJson();
490498
[@Arkhas]: https://github.com/Arkhas
491499
[@apreiml]: https://github.com/apreiml
492500
[@Stokoe0990]: https://github.com/Stokoe0990
501+
[@drsdre]: https://github.com/drsdre

src/DataTableAbstract.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
4949
* @var array
5050
*/
5151
protected $columnDef = [
52-
'index' => false,
53-
'append' => [],
54-
'edit' => [],
55-
'filter' => [],
56-
'order' => [],
57-
'only' => null,
52+
'index' => false,
53+
'append' => [],
54+
'edit' => [],
55+
'filter' => [],
56+
'order' => [],
57+
'only' => null,
58+
'hidden' => [],
5859
];
5960

6061
/**
@@ -246,6 +247,19 @@ public function escapeColumns($columns = '*')
246247
return $this;
247248
}
248249

250+
/**
251+
* Add a makeHidden() to the row object.
252+
*
253+
* @param array $attributes
254+
* @return $this
255+
*/
256+
public function makeHidden(array $attributes = [])
257+
{
258+
$this->columnDef['hidden'] = array_merge_recursive(array_get($this->columnDef, 'hidden', []), $attributes);
259+
260+
return $this;
261+
}
262+
249263
/**
250264
* Set columns that should not be escaped.
251265
* Optionally merge the defaults from config.

src/Processors/DataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function __construct($results, array $columnDef, array $templates, $start
8282
$this->escapeColumns = $columnDef['escape'];
8383
$this->includeIndex = $columnDef['index'];
8484
$this->rawColumns = $columnDef['raw'];
85+
$this->makeHidden = $columnDef['hidden'];
8586
$this->templates = $templates;
8687
$this->start = $start;
8788
}
@@ -98,7 +99,7 @@ public function process($object = false)
9899
$indexColumn = config('datatables.index_column', 'DT_RowIndex');
99100

100101
foreach ($this->results as $row) {
101-
$data = Helper::convertToArray($row);
102+
$data = Helper::convertToArray($row, ['hidden' => $this->makeHidden]);
102103
$value = $this->addColumns($data, $row);
103104
$value = $this->editColumns($value, $row);
104105
$value = $this->setupRowVariables($value, $row);

src/QueryDataTable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,12 @@ protected function globalSearch($keyword)
724724
*/
725725
protected function showDebugger(array $output)
726726
{
727-
$output['queries'] = $this->connection->getQueryLog();
727+
$query_log = $this->connection->getQueryLog();
728+
array_walk_recursive($query_log, function (&$item, $key) {
729+
$item = utf8_encode($item);
730+
});
731+
732+
$output['queries'] = $query_log;
728733
$output['input'] = $this->request->all();
729734

730735
return $output;

src/Utilities/Helper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ public static function getOrMethod($method)
151151
* Converts array object values to associative array.
152152
*
153153
* @param mixed $row
154+
* @param array $filters
154155
* @return array
155156
*/
156-
public static function convertToArray($row)
157+
public static function convertToArray($row, $filters = [])
157158
{
159+
$row = method_exists($row, 'makeHidden') ? $row->makeHidden(array_get($filters, 'hidden', [])) : $row;
158160
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
159161

160162
foreach ($data as &$value) {

0 commit comments

Comments
 (0)