@@ -112,7 +112,12 @@ public function getConfig()
112
112
*/
113
113
public function query (QueryBuilder $ builder ): QueryDataTable
114
114
{
115
- return QueryDataTable::create ($ builder );
115
+ /** @var string */
116
+ $ dataTable = config ('datatables.engines.query ' );
117
+
118
+ $ this ->validateDataTable ($ dataTable , QueryDataTable::class);
119
+
120
+ return $ dataTable ::create ($ builder );
116
121
}
117
122
118
123
/**
@@ -123,7 +128,12 @@ public function query(QueryBuilder $builder): QueryDataTable
123
128
*/
124
129
public function eloquent (EloquentBuilder $ builder ): EloquentDataTable
125
130
{
126
- return EloquentDataTable::create ($ builder );
131
+ /** @var string */
132
+ $ dataTable = config ('datatables.engines.eloquent ' );
133
+
134
+ $ this ->validateDataTable ($ dataTable , EloquentDataTable::class);
135
+
136
+ return $ dataTable ::create ($ builder );
127
137
}
128
138
129
139
/**
@@ -134,7 +144,12 @@ public function eloquent(EloquentBuilder $builder): EloquentDataTable
134
144
*/
135
145
public function collection ($ collection ): CollectionDataTable
136
146
{
137
- return CollectionDataTable::create ($ collection );
147
+ /** @var string */
148
+ $ dataTable = config ('datatables.engines.collection ' );
149
+
150
+ $ this ->validateDataTable ($ dataTable , CollectionDataTable::class);
151
+
152
+ return $ dataTable ::create ($ collection );
138
153
}
139
154
140
155
/**
@@ -163,4 +178,32 @@ public function getHtmlBuilder()
163
178
164
179
return $ this ->html ?: $ this ->html = app ('datatables.html ' );
165
180
}
181
+
182
+ /**
183
+ * @param string $engine
184
+ * @param string $parent
185
+ *
186
+ * @return void
187
+ *
188
+ * @throws \Yajra\DataTables\Exceptions\Exception
189
+ */
190
+ public function validateDataTable (string $ engine , string $ parent ): void
191
+ {
192
+ if (! ($ engine == $ parent || is_subclass_of ($ engine , $ parent ))) {
193
+ $ this ->throwInvalidEngineException ($ engine , $ parent );
194
+ }
195
+ }
196
+
197
+ /**
198
+ * @param string $engine
199
+ * @param string $parent
200
+ *
201
+ * @return void
202
+ *
203
+ * @throws \Yajra\DataTables\Exceptions\Exception
204
+ */
205
+ public function throwInvalidEngineException (string $ engine , string $ parent ): void
206
+ {
207
+ throw new Exception ("The given datatable engine ` {$ engine }` is not compatible with ` {$ parent }`. " );
208
+ }
166
209
}
0 commit comments