@@ -114,11 +114,8 @@ public function query(QueryBuilder $builder): QueryDataTable
114114 {
115115 $ dataTable = config ('datatables.engines.query ' );
116116
117- if (! is_subclass_of ($ dataTable , QueryDataTable::class)) {
118- $ this ->throwInvalidEngineException ($ dataTable , QueryDataTable::class);
119- }
117+ $ this ->validateDataTable ($ dataTable , QueryDataTable::class);
120118
121- /** @phpstan-ignore-next-line */
122119 return $ dataTable ::create ($ builder );
123120 }
124121
@@ -132,11 +129,8 @@ public function eloquent(EloquentBuilder $builder): EloquentDataTable
132129 {
133130 $ dataTable = config ('datatables.engines.eloquent ' );
134131
135- if (! is_subclass_of ($ dataTable , EloquentDataTable::class)) {
136- $ this ->throwInvalidEngineException ($ dataTable , EloquentDataTable::class);
137- }
132+ $ this ->validateDataTable ($ dataTable , EloquentDataTable::class);
138133
139- /** @phpstan-ignore-next-line */
140134 return $ dataTable ::create ($ builder );
141135 }
142136
@@ -150,11 +144,8 @@ public function collection($collection): CollectionDataTable
150144 {
151145 $ dataTable = config ('datatables.engines.collection ' );
152146
153- if (! is_subclass_of ($ dataTable , CollectionDataTable::class)) {
154- $ this ->throwInvalidEngineException ($ dataTable , CollectionDataTable::class);
155- }
147+ $ this ->validateDataTable ($ dataTable , CollectionDataTable::class);
156148
157- /** @phpstan-ignore-next-line */
158149 return $ dataTable ::create ($ collection );
159150 }
160151
@@ -177,7 +168,22 @@ public function getHtmlBuilder()
177168 /**
178169 * @param string $engine
179170 * @param string $parent
180- *
171+ *
172+ * @return void
173+ *
174+ * @throws \Yajra\DataTables\Exceptions\Exception
175+ */
176+ public function validateDataTable (string $ engine , string $ parent )
177+ {
178+ if (! ($ engine == $ parent || is_subclass_of ($ engine , $ parent ))) {
179+ $ this ->throwInvalidEngineException ($ engine , $ parent );
180+ }
181+ }
182+
183+ /**
184+ * @param string $engine
185+ * @param string $parent
186+ *
181187 * @throws \Yajra\DataTables\Exceptions\Exception
182188 */
183189 public function throwInvalidEngineException (string $ engine , string $ parent )
0 commit comments