Skip to content

Commit 7e6c66d

Browse files
committed
Add brief documentation and example
1 parent 114da04 commit 7e6c66d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ composer require langleyfoxall/react-dynamic-data-table-laravel-api
1414

1515
First, create a new route in your API routes file for the data table response, and point it to a controller.
1616

17-
In this controller method, create a new `DataTableResponder` passing it the model you wish to return data about, and the provided instance of the `Request` object. You can optionally specify changes to the query (such as sorting, or filtering) using the `query` method. You can also change number of records shown per page with the `setPerPage` method.
17+
In this controller method, create a new `DataTableResponder` passing it the model you wish to return data about, and the provided instance of the `Request` object. You can optionally specify changes to the query (such as sorting, or filtering) using the `query` method. If you want to alter the data before it gets return, such as loading relationships or appending custom attributes you can take advantage of `collectionManipulator`. You can also change number of records shown per page with the `setPerPage` method.
1818

1919
See the example usage below.
2020

@@ -28,10 +28,15 @@ class UsersController extends Controller
2828
public function dataTable(Request $request)
2929
{
3030
return (new DataTableResponder(User::class, $request))
31-
->query(function($query) { // Optional, default: none
31+
->query(function($query) { // Optional, default: none
3232
$query->where('name', 'like', 'B%');
3333
})
34-
->setPerPage(10) // Optional, default: 15
34+
->collectionManipulator(function (Collection $collection) { // Optional, default: none
35+
$collection->map(function($user) {
36+
$user->name = title_case($user->name);
37+
});
38+
})
39+
->setPerPage(10) // Optional, default: 15
3540
->respond();
3641
}
3742
}

0 commit comments

Comments
 (0)