@@ -113,7 +113,11 @@ public function getConfig()
113113 public function query (QueryBuilder $ builder ): QueryDataTable
114114 {
115115 $ dataTable = config ('datatables.engines.query ' );
116-
116+
117+ if (! is_subclass_of ($ dataTable , QueryDataTable::class)) {
118+ $ this ->throwInvalidEngineException ($ dataTable , QueryDataTable::class);
119+ }
120+
117121 return $ dataTable ::create ($ builder );
118122 }
119123
@@ -126,7 +130,11 @@ public function query(QueryBuilder $builder): QueryDataTable
126130 public function eloquent (EloquentBuilder $ builder ): EloquentDataTable
127131 {
128132 $ dataTable = config ('datatables.engines.eloquent ' );
129-
133+
134+ if (! is_subclass_of ($ dataTable , EloquentDataTable::class)) {
135+ $ this ->throwInvalidEngineException ($ dataTable , EloquentDataTable::class);
136+ }
137+
130138 return $ dataTable ::create ($ builder );
131139 }
132140
@@ -139,7 +147,11 @@ public function eloquent(EloquentBuilder $builder): EloquentDataTable
139147 public function collection ($ collection ): CollectionDataTable
140148 {
141149 $ dataTable = config ('datatables.engines.collection ' );
142-
150+
151+ if (! is_subclass_of ($ dataTable , CollectionDataTable::class)) {
152+ $ this ->throwInvalidEngineException ($ dataTable , CollectionDataTable::class);
153+ }
154+
143155 return $ dataTable ::create ($ collection );
144156 }
145157
@@ -158,4 +170,15 @@ public function getHtmlBuilder()
158170
159171 return $ this ->html ?: $ this ->html = app ('datatables.html ' );
160172 }
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+ }
161184}
0 commit comments