Skip to content

Commit a401281

Browse files
committed
enable Carbon usage for timestamps
update read me fix doc block for filter
1 parent 87519b5 commit a401281

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the `yajra/datatables` under the `require` key after that run the `composer
1818
```php
1919
{
2020
"require": {
21-
"laravel/framework": "4.1.*",
21+
"laravel/framework": "4.2.*",
2222
...
2323
"yajra/laravel-datatables-oracle": "*"
2424
}
@@ -91,11 +91,27 @@ It is better, you know these:
9191
->make();
9292
```
9393

94-
**Example 3:**
94+
**Example 3: Overriding default filter option**
9595
```php
9696
$posts = Post::select(array('posts.id','posts.name','posts.created_at','posts.status'));
9797

98-
return Datatables::of($posts)->filter(function($query){
98+
return Datatables::of($posts)
99+
->filter(function($query){
100+
if (Input::get('id')) {
101+
$query->where('id','=',Input::get('id'));
102+
}
103+
})->make();
104+
```
105+
106+
**Example 4: Accessing Carbon object on timestamps**
107+
> Note: You cannot access Carbon object using blade templating approach
108+
109+
```php
110+
$posts = Post::select(array('posts.id','posts.name','posts.created_at','posts.status'));
111+
112+
return Datatables::of($posts)
113+
->editColumn('created_at', function($data){ $data->created_at->toDateTimeString() })
114+
->filter(function($query){
99115
if (Input::get('id')) {
100116
$query->where('id','=',Input::get('id'));
101117
}

src/yajra/Datatables/Datatables.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function of($query)
6161
// set connection and query variable
6262
if($ins->query_type == 'eloquent') {
6363
$ins->connection = $ins->query->getModel()->getConnection();
64-
$ins->query = $ins->query->getQuery();
64+
$ins->query = $query;
6565
}
6666
else {
6767
$ins->connection = $query->getConnection();
@@ -108,7 +108,12 @@ public function make($mDataSupport=false)
108108
private function getResult()
109109
{
110110
$this->result_object = $this->query->get();
111-
$this->result_array = array_map(function($object) { return (array) $object; }, $this->result_object);
111+
if ($this->query_type == 'eloquent') {
112+
$this->result_array = array_map(function($object) { return (array) $object; }, $this->result_object->toArray());
113+
}
114+
else {
115+
$this->result_array = array_map(function($object) { return (array) $object; }, (array) $this->result_object);
116+
}
112117
}
113118

114119
/**
@@ -393,8 +398,9 @@ private function cleanColumns( $cols, $use_alias = true )
393398
}
394399

395400
/**
396-
* set auto filter off
397-
* @return [type] [description]
401+
* set auto filter off and run your own filter
402+
* @param Closure
403+
* @return Datatables
398404
*/
399405
public function filter(Closure $callback)
400406
{

0 commit comments

Comments
 (0)