@@ -114,11 +114,8 @@ 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
- }
117
+ $ this ->validateDataTable ($ dataTable , QueryDataTable::class);
120
118
121
- /** @phpstan-ignore-next-line */
122
119
return $ dataTable ::create ($ builder );
123
120
}
124
121
@@ -132,11 +129,8 @@ public function eloquent(EloquentBuilder $builder): EloquentDataTable
132
129
{
133
130
$ dataTable = config ('datatables.engines.eloquent ' );
134
131
135
- if (! is_subclass_of ($ dataTable , EloquentDataTable::class)) {
136
- $ this ->throwInvalidEngineException ($ dataTable , EloquentDataTable::class);
137
- }
132
+ $ this ->validateDataTable ($ dataTable , EloquentDataTable::class);
138
133
139
- /** @phpstan-ignore-next-line */
140
134
return $ dataTable ::create ($ builder );
141
135
}
142
136
@@ -150,11 +144,8 @@ public function collection($collection): CollectionDataTable
150
144
{
151
145
$ dataTable = config ('datatables.engines.collection ' );
152
146
153
- if (! is_subclass_of ($ dataTable , CollectionDataTable::class)) {
154
- $ this ->throwInvalidEngineException ($ dataTable , CollectionDataTable::class);
155
- }
147
+ $ this ->validateDataTable ($ dataTable , CollectionDataTable::class);
156
148
157
- /** @phpstan-ignore-next-line */
158
149
return $ dataTable ::create ($ collection );
159
150
}
160
151
@@ -177,7 +168,22 @@ public function getHtmlBuilder()
177
168
/**
178
169
* @param string $engine
179
170
* @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
+ *
181
187
* @throws \Yajra\DataTables\Exceptions\Exception
182
188
*/
183
189
public function throwInvalidEngineException (string $ engine , string $ parent )
0 commit comments