Skip to content

Commit 20cc622

Browse files
authored
Merge pull request yajra#2263 from imTigger/master
[9.0] Add the possibility to makeVisible() some attribute of a model.
2 parents c524b85 + ad69720 commit 20cc622

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/DataTableAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
5757
'order' => [],
5858
'only' => null,
5959
'hidden' => [],
60+
'visible' => [],
6061
];
6162

6263
/**
@@ -261,6 +262,19 @@ public function makeHidden(array $attributes = [])
261262
return $this;
262263
}
263264

265+
/**
266+
* Add a makeVisible() to the row object.
267+
*
268+
* @param array $attributes
269+
* @return $this
270+
*/
271+
public function makeVisible(array $attributes = [])
272+
{
273+
$this->columnDef['visible'] = array_merge_recursive(Arr::get($this->columnDef, 'visible', []), $attributes);
274+
275+
return $this;
276+
}
277+
264278
/**
265279
* Set columns that should not be escaped.
266280
* Optionally merge the defaults from config.

src/Processors/DataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function __construct($results, array $columnDef, array $templates, $start
8383
$this->includeIndex = $columnDef['index'];
8484
$this->rawColumns = $columnDef['raw'];
8585
$this->makeHidden = $columnDef['hidden'];
86+
$this->makeVisible = $columnDef['visible'];
8687
$this->templates = $templates;
8788
$this->start = $start;
8889
}
@@ -99,7 +100,7 @@ public function process($object = false)
99100
$indexColumn = config('datatables.index_column', 'DT_RowIndex');
100101

101102
foreach ($this->results as $row) {
102-
$data = Helper::convertToArray($row, ['hidden' => $this->makeHidden]);
103+
$data = Helper::convertToArray($row, ['hidden' => $this->makeHidden, 'visible' => $this->makeVisible]);
103104
$value = $this->addColumns($data, $row);
104105
$value = $this->editColumns($value, $row);
105106
$value = $this->setupRowVariables($value, $row);

src/Utilities/Helper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public static function getOrMethod($method)
158158
public static function convertToArray($row, $filters = [])
159159
{
160160
$row = method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
161+
$row = method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
161162
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
162163

163164
foreach ($data as &$value) {

0 commit comments

Comments
 (0)