@@ -113,7 +113,11 @@ public function getConfig()
113
113
public function query (QueryBuilder $ builder ): QueryDataTable
114
114
{
115
115
$ dataTable = config ('datatables.engines.query ' );
116
-
116
+
117
+ if (! is_subclass_of ($ dataTable , QueryDataTable::class)) {
118
+ $ this ->throwInvalidEngineException ($ dataTable , QueryDataTable::class);
119
+ }
120
+
117
121
return $ dataTable ::create ($ builder );
118
122
}
119
123
@@ -126,7 +130,11 @@ public function query(QueryBuilder $builder): QueryDataTable
126
130
public function eloquent (EloquentBuilder $ builder ): EloquentDataTable
127
131
{
128
132
$ dataTable = config ('datatables.engines.eloquent ' );
129
-
133
+
134
+ if (! is_subclass_of ($ dataTable , EloquentDataTable::class)) {
135
+ $ this ->throwInvalidEngineException ($ dataTable , EloquentDataTable::class);
136
+ }
137
+
130
138
return $ dataTable ::create ($ builder );
131
139
}
132
140
@@ -139,7 +147,11 @@ public function eloquent(EloquentBuilder $builder): EloquentDataTable
139
147
public function collection ($ collection ): CollectionDataTable
140
148
{
141
149
$ dataTable = config ('datatables.engines.collection ' );
142
-
150
+
151
+ if (! is_subclass_of ($ dataTable , CollectionDataTable::class)) {
152
+ $ this ->throwInvalidEngineException ($ dataTable , CollectionDataTable::class);
153
+ }
154
+
143
155
return $ dataTable ::create ($ collection );
144
156
}
145
157
@@ -158,4 +170,15 @@ public function getHtmlBuilder()
158
170
159
171
return $ this ->html ?: $ this ->html = app ('datatables.html ' );
160
172
}
173
+
174
+ /**
175
+ * @param string $engine
176
+ * @param string $parent
177
+ *
178
+ * @throws \Yajra\DataTables\Exceptions\Exception
179
+ */
180
+ public function throwInvalidEngineException (string $ engine , string $ parent )
181
+ {
182
+ throw new Exception ("The given datatable engine ` {$ engine }` is not compatible with ` {$ parent }`. " );
183
+ }
161
184
}
0 commit comments