Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eloquent DataTables casts all attributes to string #1747

Closed
peyobr opened this issue May 23, 2018 · 11 comments
Closed

Eloquent DataTables casts all attributes to string #1747

peyobr opened this issue May 23, 2018 · 11 comments

Comments

@peyobr
Copy link

peyobr commented May 23, 2018

Eloquent DataTables casts all attributes to string

Eloquent DataTables casts all attributes to string, even int ids, even if explicit eloquent model $casts is set.

Code snippet of problem

System details

  • Linux Mint 18.3
  • PHP 7.0.30-0ubuntu0.16.04.1
  • Laravel Version 5.5.40
  • Laravel-Datatables Version 8.6.0
  • Mysql 5.5.72-ubuntu0.16.04.1
@BARNZ
Copy link

BARNZ commented Sep 12, 2018

I encountered this problem today as well. Wondering why this would be happening?

What I'm getting:

image

What I expect:

image

@yajra
Copy link
Owner

yajra commented Sep 12, 2018

Found the related issue/pr: yajra/laravel-datatables-buttons#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!

ridaamirini added a commit to ridaamirini/laravel-datatables that referenced this issue Dec 21, 2018
@ridaamirini
Copy link
Contributor

@yajra I added a PR

yajra added a commit that referenced this issue Jan 4, 2019
[8.0] Keep casted attributes #1747
@yajra
Copy link
Owner

yajra commented Jan 4, 2019

Fixed on v8.13.2, thanks to @ridaamirini!

@yajra yajra closed this as completed Jan 4, 2019
yajra added a commit that referenced this issue Jan 5, 2019
Revert "[8.0] Keep casted attributes #1747"
@jovpet
Copy link

jovpet commented Oct 16, 2019

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 ?

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);
    }
`

@yajra
Copy link
Owner

yajra commented Oct 16, 2019

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.

@rilwanmsm
Copy link

Any updates?

@fayaz668
Copy link

fayaz668 commented Jan 6, 2020

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??

@ridaamirini
Copy link
Contributor

@rilwanmsm @fayaz668 I don't think this will be fixed...

@yajra
Copy link
Owner

yajra commented Jan 7, 2020

Can't check this further atm. Maybe you guys can provide some tests / feedbacks on #1951?

@yajra yajra reopened this Jan 7, 2020
@fayaz668
Copy link

@yajra , @ridaamirini below methods works for me

return \DataTables::eloquent(Users::where('isActive',1))
      ->rawColumns(['id'])
      ->make(true);

@yajra yajra closed this as completed May 30, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants