You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://packagist.org/packages/hamidrrj/laravel-datatable)
[](https://packagist.org/packages/hamidrezarj/laravel-datatable)
Here's an example of filtering users whose usernames contain 'sth', sorted by creation date in descending order:
94
+
```php
95
+
$requestParameters = [
96
+
'start' => 10,
97
+
'size' => 10,
98
+
'filters' => [
99
+
[
100
+
'id' => 'username',
101
+
'value' => 'sth',
102
+
'fn' => 'contains',
103
+
'datatype' => 'text'
104
+
]
105
+
],
106
+
'sorting' => [
107
+
[
108
+
'id' => 'created_at',
109
+
'desc' => true,
110
+
]
111
+
]
112
+
];
113
+
114
+
$allowedFilters = ['username'];
115
+
$allowedSortings = ['created_at'];
116
+
117
+
$data = DatatableFacade::run(
118
+
$query,
119
+
$requestParameters,
120
+
$allowedFilters,
121
+
$allowedSortings
122
+
);
123
+
```
124
+
**Note**: Ensure that columns used for filtering and sorting are included in the `$allowedFilters` and `$allowedSortings` arrays to avoid `InvalidFilterException` and `InvalidSortingException`.
125
+
126
+
### Method Parameters
127
+
The `run` method of `DatatableFacade` accepts the following parameters:
128
+
129
+
1.`$mixed`: Model instance or query builder instance to perform queries on.
130
+
2.`$requestParameters`: Contains parameters like `filter`, `sorting`, `size`, and `start` of required data.
131
+
3.`$allowedFilters`: (Optional) Specifies columns users are allowed to filter on.
132
+
4.`$allowedSortings`: (Optional) Specifies columns users are allowed to sort on.
133
+
5.`$allowedSelects`: (Optional) Specifies which columns users can actually see.
134
+
6.`$allowedRelations`: (Optional) Specifies which model relations users are allowed to filter on.
135
+
136
+
### Filter Array Structure
137
+
Each filter in the `filters` array should have the following attributes:
138
+
-`id`: Name of the column to filter on
139
+
-`value`: Value of the filter
140
+
-`fn`: Type of filter to apply (e.g., contains, between, equals, less than)
141
+
-`datatype`: Type of column (e.g., text, numeric, date)
142
+
143
+
### Return Data Structure
144
+
The `run` method returns an array with the following structure:
55
145
```php
56
-
$laravelDatatable = new HamidRrj\LaravelDatatable();
0 commit comments