1313use Illuminate \Database \Eloquent \Relations \Relation ;
1414use Illuminate \Validation \ValidationException ;
1515
16+ /**
17+ * @template T
18+ */
1619class BaseQueryBuilderExtend
1720{
1821 use QueryOrder {
@@ -217,11 +220,11 @@ public function orWhereHas(string $relation, Closure|null $callback = null, stri
217220 /**
218221 * @param array|string $column
219222 * @param string|null $operator
220- * @param string|null $value
223+ * @param mixed $value
221224 * @param string|null $boolean
222225 * @return BaseQueryBuilder
223226 */
224- public function where (array |string $ column , ?string $ operator = null , ? string $ value = null , ?string $ boolean = 'and ' ): BaseQueryBuilder
227+ public function where (array |string $ column , ?string $ operator = null , mixed $ value = null , ?string $ boolean = 'and ' ): BaseQueryBuilder
225228 {
226229 $ this ->builder ->where ($ column , $ operator , $ value , $ boolean );
227230 return $ this ->baseQueryBuilder ;
@@ -231,10 +234,10 @@ public function where(array|string $column, ?string $operator = null, ?string $v
231234 /**
232235 * @param array|string $column
233236 * @param string|null $operator
234- * @param string|null $value
237+ * @param mixed $value
235238 * @return BaseQueryBuilder
236239 */
237- public function orWhere (array |string $ column , ?string $ operator = null , ? string $ value = null ): BaseQueryBuilder
240+ public function orWhere (array |string $ column , ?string $ operator = null , mixed $ value = null ): BaseQueryBuilder
238241 {
239242 $ this ->builder ->orWhere ($ column , $ operator , $ value );
240243 return $ this ->baseQueryBuilder ;
@@ -244,11 +247,11 @@ public function orWhere(array|string $column, ?string $operator = null, ?string
244247 /**
245248 * @param $column
246249 * @param string|null $operator
247- * @param string|null $value
250+ * @param mixed $value
248251 * @param string|null $boolean
249252 * @return BaseQueryBuilder
250253 */
251- public function whereNot ($ column , ?string $ operator = null , ? string $ value = null , ?string $ boolean = 'and ' ): BaseQueryBuilder
254+ public function whereNot ($ column , ?string $ operator = null , mixed $ value = null , ?string $ boolean = 'and ' ): BaseQueryBuilder
252255 {
253256 $ this ->builder ->whereNot ($ column , $ operator , $ value , $ boolean );
254257 return $ this ->baseQueryBuilder ;
@@ -257,12 +260,12 @@ public function whereNot($column, ?string $operator = null, ?string $value = nul
257260
258261 /**
259262 * @param string $column
260- * @param array $values
263+ * @param iterable $values
261264 * @param string $boolean
262265 * @param bool $not
263266 * @return BaseQueryBuilder
264267 */
265- public function whereBetween (string $ column , array $ values , string $ boolean = 'and ' , bool $ not = false ): BaseQueryBuilder
268+ public function whereBetween (string $ column , iterable $ values , string $ boolean = 'and ' , bool $ not = false ): BaseQueryBuilder
266269 {
267270 $ this ->builder ->whereBetween ($ column , $ values , $ boolean , $ not );
268271 return $ this ->baseQueryBuilder ;
@@ -271,11 +274,11 @@ public function whereBetween(string $column, array $values, string $boolean = 'a
271274
272275 /**
273276 * @param string $column
274- * @param array|string $values
277+ * @param iterable $values
275278 * @param string $boolean
276279 * @return BaseQueryBuilder
277280 */
278- public function whereNotBetween (string $ column , array | string $ values , string $ boolean = 'and ' ): BaseQueryBuilder
281+ public function whereNotBetween (string $ column , iterable $ values , string $ boolean = 'and ' ): BaseQueryBuilder
279282 {
280283 $ this ->builder ->whereNotBetween ($ column , $ values , $ boolean );
281284 return $ this ->baseQueryBuilder ;
@@ -453,62 +456,73 @@ public function orWhereColumn(array|string $first, ?string $operator = null, ?st
453456
454457 /**
455458 * @param array $whereClause
456- * @param array $columns
459+ * @param array|null $columns
457460 * @param int|null $perPage
458461 * @return LengthAwarePaginator
459462 */
460- public function getAllDataPaginated (array $ whereClause = [], array $ columns = [ " * " ] , ?int $ perPage = null ):LengthAwarePaginator
463+ public function getAllDataPaginated (array $ whereClause = [], array | null $ columns = null , ?int $ perPage = null ): LengthAwarePaginator
461464 {
462465 if (!$ perPage ) {
463- $ perPage = request ()->query ("perpage " , config ('queryextend.perpage ' ));
466+ $ perPage = request ()->query (config ("queryextend.perpage.key " ), config ('queryextend.perpage.value ' ));
467+ }
468+
469+ if ($ columns ) {
470+ $ this ->builder ->addSelect ($ columns );
464471 }
465472 return $ this ->builder
466- ->select ($ columns )
467473 ->where ($ whereClause )
468474 ->paginate ($ perPage );
469475 }
470476
471477 /**
472478 * @param array $whereClause
473- * @param array $columns
474- * @return Builder[]| Collection
479+ * @param array|null $columns
480+ * @return Collection
475481 */
476- public function getAllData (array $ whereClause = [], array $ columns = [ " * " ] ): Collection | array
482+ public function getAllData (array $ whereClause = [], array | null $ columns = null ): Collection
477483 {
484+ if ($ columns ) {
485+ $ this ->builder ->addSelect ($ columns );
486+ }
478487 return $ this ->builder
479- ->select ($ columns )
480488 ->where ($ whereClause )
481489 ->get ();
482490 }
483491
484492 /**
485493 * @param string|int|array $id
486- * @param array $columns
487- * @return Builder|Builder[]|Collection|Model |null
494+ * @param array|null $columns
495+ * @return Builder|Builder[]|Collection|T |null
488496 */
489- public function getDataById (string |int |array $ id , array $ columns = [ " * " ])
497+ public function getDataById (string |int |array $ id , array | null $ columns = null ): Model | Collection | Builder | array | null
490498 {
491- return $ this ->builder ->select ($ columns )->find ($ id );
499+ if ($ columns ) {
500+ $ this ->builder ->addSelect ($ columns );
501+ }
502+ return $ this ->builder ->find ($ id );
492503 }
493504
494505 /**
495506 * @param array $whereClause
496- * @param array $columns
497- * @return Builder|Model|object |null
507+ * @param array|null $columns
508+ * @return Builder|T |null
498509 */
499- public function getSingleData (array $ whereClause = [], array $ columns = [ " * " ])
510+ public function getSingleData (array $ whereClause = [], array | null $ columns = null ): Model | Builder | null
500511 {
512+ if ($ columns ) {
513+ $ this ->builder ->addSelect ($ columns );
514+ }
501515 return $ this ->builder
502- ->select ($ columns )
503516 ->where ($ whereClause )
504517 ->first ();
505518 }
506519
507520 /**
521+ *
508522 * @param array $requestedData
509- * @return Builder|Model
523+ * @return T|Builder
510524 */
511- public function addNewData (array $ requestedData )
525+ public function addNewData (array $ requestedData ): Model | Builder
512526 {
513527 return $ this ->builder ->create ($ requestedData );
514528 }
@@ -531,7 +545,7 @@ public function addMultipleData(array $requestedData): int
531545 * @param bool $isReturnObject
532546 * @return Builder|Builder[]|Collection|Model|int|null
533547 */
534- public function updateDataById (string |int $ id , array $ requestedData , array $ columns = ["* " ], bool $ isReturnObject = true )
548+ public function updateDataById (string |int $ id , array $ requestedData , array $ columns = ["* " ], bool $ isReturnObject = true ): Model | Collection | Builder | int | array | null
535549 {
536550 $ updatedData = $ this ->builder
537551 ->where ("id " , $ id )
@@ -547,9 +561,9 @@ public function updateDataById(string|int $id, array $requestedData, array $colu
547561 * @param array $requestedData
548562 * @param array $columns
549563 * @param bool $isReturnObject
550- * @return Collection|int|null
564+ * @return Collection|int
551565 */
552- public function updateDataByWhereClause (array $ whereClause , array $ requestedData , array $ columns = ["* " ], bool $ isReturnObject = false )
566+ public function updateDataByWhereClause (array $ whereClause , array $ requestedData , array $ columns = ["* " ], bool $ isReturnObject = false ): Collection | int
553567 {
554568 $ updatedData = $ this ->builder
555569 ->where ($ whereClause )
@@ -563,7 +577,7 @@ public function updateDataByWhereClause(array $whereClause, array $requestedData
563577 * @param string|int $id
564578 * @return mixed
565579 */
566- public function deleteDataById (string |int $ id )
580+ public function deleteDataById (string |int $ id ): mixed
567581 {
568582 return $ this ->builder
569583 ->where ("id " , $ id )
@@ -574,7 +588,7 @@ public function deleteDataById(string|int $id)
574588 * @param array $whereClause
575589 * @return mixed
576590 */
577- public function deleteDataByWhereClause (array $ whereClause )
591+ public function deleteDataByWhereClause (array $ whereClause ): mixed
578592 {
579593 return $ this ->builder
580594 ->where ($ whereClause )
0 commit comments