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
This section covers various use cases and features of Laravel Datatable. From basic querying to advanced filtering and relationship handling, you'll find examples to help you make the most of this package.
The `run` method of `DatatableFacade` accepts the following parameters:
74
+
75
+
1.`$mixed`: Model instance or query builder instance to perform queries on.
76
+
2.`$requestParameters`: Contains parameters like `filter`, `sorting`, `size`, and `start` of required data.
77
+
3.`$allowedFilters`: (Optional) Specifies columns users are allowed to filter on.
78
+
4.`$allowedSortings`: (Optional) Specifies columns users are allowed to sort on.
79
+
5.`$allowedSelects`: (Optional) Specifies which columns users can actually see.
80
+
6.`$allowedRelations`: (Optional) Specifies which model relations users are allowed to filter on.
81
+
82
+
### Filter Array Structure
83
+
84
+
Each filter in the `filters` array should have the following attributes:
85
+
86
+
-`id`: Name of the column to filter on. When filtering a relationship's attribute, use the format: `relationName.attribute`. (`relationName` must exist as a `HasOne` or `HasMany` relationship in the base Model, e.g., User model)
87
+
-`value`: Value of the filter
88
+
- For most filter types: a single value
89
+
- For `fn = 'between'`: an array of two values, e.g., `[min, max]`
90
+
-`fn`: Type of filter to apply. Available options include:
91
+
-`contains`
92
+
-`between`
93
+
-`equals`
94
+
-`notEquals`
95
+
-`lessThan`
96
+
-`lessThanOrEqual`
97
+
-`greaterThan`
98
+
-`greaterThanOrEqual`
99
+
-`datatype`: Type of column. Options include:
100
+
-`text`
101
+
-`numeric`
102
+
-`date`
103
+
104
+
### Return Data Structure
105
+
106
+
The `run` method returns an array with the following structure:
107
+
108
+
```php
109
+
[
110
+
"data" => [
111
+
// Array of matching records
112
+
],
113
+
"meta" => [
114
+
"totalRowCount" => 10 // Total count of matching records
115
+
]
116
+
]
117
+
```
118
+
59
119
### Basic Usage
60
120
61
121
Here's a simple example of requesting a chunk of 10 users starting from the 11th record (i.e., page 2 of the datatable):
**Note**: Ensure that columns used for filtering and sorting are included in the `$allowedFilters` and `$allowedSortings` arrays to avoid `InvalidFilterException` and `InvalidSortingException`.
125
187
126
-
### Method Parameters
127
-
The `run` method of `DatatableFacade` accepts the following parameters:
188
+
### Using `between` search function
189
+
Here's an example of filtering users whose creation dates are between two dates:
190
+
```php
191
+
$query = User::query()
128
192
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.
0 commit comments