@@ -15,13 +15,11 @@ public function __construct(
1515 protected array $ columns = [],
1616 protected bool $ useScout = true ,
1717 protected int $ perPage = 10 ,
18- )
19- { }
18+ ) {
19+ }
2020
2121 /**
2222 * Builds the query and returns the paginator
23- *
24- * @return LengthAwarePaginator
2523 */
2624 public function response (): LengthAwarePaginator
2725 {
@@ -35,30 +33,30 @@ public function response(): LengthAwarePaginator
3533 $ scoutKeys = []; // Stores Laravel scout temporary keys
3634
3735 // If none is filled, return teh latest paginated results
38- if (! filled ($ searchQuery ) && !filled ($ values )){
36+ if (! filled ($ searchQuery ) && ! filled ($ values )) {
3937 return $ model ::query ()->latest ()->paginate ($ this ->perPage );
4038 }
4139
42- if ($ this ->useScout && in_array (Searchable::class, class_uses ($ model ::class))){
40+ if ($ this ->useScout && in_array (Searchable::class, class_uses ($ model ::class))) {
4341 /** @var Searchable $model */
4442 $ scoutKeys = $ model ::search ($ searchQuery ?? '' )->keys () ?? [];
4543 }
4644
4745 return $ model ::query ()
4846 // If we have values, then we can instantly filter them here
49- ->when (filled ($ values ), function ($ query ) use ($ model , $ values ) {
50- $ query ->whereIn ($ model ->getKeyName (), !is_array ($ values ) ? Str::of ($ values )->explode (', ' ) : $ values );
47+ ->when (filled ($ values ), function ($ query ) use ($ model , $ values ) {
48+ $ query ->whereIn ($ model ->getKeyName (), ! is_array ($ values ) ? Str::of ($ values )->explode (', ' ) : $ values );
5149 })
5250 // Not using scout and using regular search
53- ->when (!$ this ->useScout && filled ($ searchQuery ) && !empty ($ this ->columns ), function ($ query ) use ( $ model , $ searchQuery, $ scoutKeys ) {
54- $ query ->where (function ($ query ) use ($ searchQuery, $ model , $ scoutKeys ) {
51+ ->when (! $ this ->useScout && filled ($ searchQuery ) && ! empty ($ this ->columns ), function ($ query ) use ( $ searchQuery ) {
52+ $ query ->where (function ($ query ) use ($ searchQuery ) {
5553 foreach ($ this ->columns as $ column ) {
5654 $ query ->orWhere ($ column , 'like ' , "% {$ searchQuery }% " );
5755 }
5856 });
5957 })
6058 // Using Scout
61- ->when ($ this ->useScout && filled ($ searchQuery ) && !empty ($ scoutKeys ), function ($ query ) use ($ model , $ scoutKeys ) {
59+ ->when ($ this ->useScout && filled ($ searchQuery ) && ! empty ($ scoutKeys ), function ($ query ) use ($ model , $ scoutKeys ) {
6260 $ query ->whereIn ($ model ->getKeyName (), $ scoutKeys );
6361 })
6462 // Finally paginate the results
@@ -70,10 +68,6 @@ public function response(): LengthAwarePaginator
7068 * Supporting scout searching
7169 * This function is intended to be used for frontend pooling with Rich Select
7270 *
73- * @param string $model
74- * @param array $columns
75- * @param bool $useScout
76- * @return LengthAwarePaginator
7771 * @throws \Exception
7872 */
7973 public static function for (string $ model , array $ columns = [], bool $ useScout = true ): LengthAwarePaginator
0 commit comments