bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

Carbon doesn't work #92

Closed eloypr closed 10 years ago

eloypr commented 10 years ago

Datetime Carbon doesn't work:

return Datatables::of($users)
    ->edit_column(
        'created_at',
        '{{ $created_at->format(\'d/m/Y H:i\') }}'
);

But it works:

return Datatables::of($users)
    ->edit_column(
        'created_at',
        '{{ date(\'d/m/Y H:i\', strtotime($created_at)) }}'
);

Can update for compatiblility with Carbon?

MarkVaughn commented 10 years ago

Sorry I have not worked with carbon, if you know what the issue is feel free to create a pull request and I'll look at it

reneweteling commented 10 years ago

@eloypr its not that datatables is not working with carbon, its more that datatables is not working with the custom getters of the model ( just getting the data from the db ) you could solve it by doing this:

{{ User::find($id)->created_at->format(etc..) }}

this way you get the item from the model using lazy loading.

cheers

gcphost commented 10 years ago

This is what I do: ->edit_column('updated_at', '{{{ Carbon::parse($updated_at)->diffForHumans() }}}')

reneweteling commented 10 years ago

@gcphost my point is more that if you can give a Eloquent reference to DataTables, you should be able to use the custom getters / setters from this model instead of creating some sort of sql query and using that.

in other words if i add an function getFooAttribute(){ return 'bar'; } id expect when selecting User::select('id','user', 'bar') that the bar getter is invoked

thanks for your reply though, but this a hack, not a solution :)

ktunkiewicz commented 10 years ago

This package currently does not work with Eloquent relations, custom getters and setters etc. Eloquent models are handled as if they were Query Builder objects. This may change in future versions but for now it's not possible to use ORM functionality.