Eloquent DataTables casts all attributes to string, even int ids, even if explicit eloquent model $casts is set.
I encountered this problem today as well. Wondering why this would be happening?
What I'm getting:

What I expect:

Found the related issue/pr: https://github.com/yajra/laravel-datatables-buttons/pull/67.
ATM, I think you need to use fractal integration for proper API response but I also agree that we can improve the package not to casts all data to string and let the eloquent casting handle it.
Can't check this further though but will definitely implement this when I got the chance. If any of you can, please do not hesitate to submit a PR. Thanks!
@yajra I added a PR
Fixed on v8.13.2, thanks to @ridaamirini!
What have happened with that? It seems it has been reverted in version 9! DataProcessor.php
It seems this PR from @ridaamirini has been discarded. @yajra ?
```php
protected function escapeColumns(array $output)
{
return array_map(function ($row) {
if ($this->escapeColumns == '*') {
$row = $this->escapeRow($row);
} elseif (is_array($this->escapeColumns)) {
$columns = array_diff($this->escapeColumns, $this->rawColumns);
foreach ($columns as $key) {
Arr::set($row, $key, e(Arr::get($row, $key)));
}
}
return $row;
}, $output);
}
`
It was reverted due to a breaking change and still unresolved. https://github.com/yajra/laravel-datatables/issues/1951. Will try to have a look at this again when I got the chance.
Any updates?
It was reverted due to a breaking change and still unresolved. #1951. Will try to have a look at this again when I got the chance.
any updates??
@rilwanmsm @fayaz668 I don't think this will be fixed...
Can't check this further atm. Maybe you guys can provide some tests / feedbacks on https://github.com/yajra/laravel-datatables/issues/1951?
@yajra , @ridaamirini below methods works for me
return \DataTables::eloquent(Users::where('isActive',1))
->rawColumns(['id'])
->make(true);
Most helpful comment
Fixed on v8.13.2, thanks to @ridaamirini!