@@ -31,38 +31,72 @@ public function apply(Builder $builder, Model $model): void
3131 public function extend (Builder $ builder ): void
3232 {
3333 $ builder ->macro ('whereConfig ' , [static ::class, 'whereConfig ' ]);
34+ $ builder ->macro ('orWhereConfig ' , [static ::class, 'orWhereConfig ' ]);
3435 }
3536
3637 /**
3738 * Filters the user by the config value.
3839 *
3940 * @param \Illuminate\Database\Eloquent\Builder $builder
4041 * @param string|array $name
41- * @param mixed|null $value
42+ * @param string|null $operator
43+ * @param null $value
44+ * @param string $boolean
4245 *
4346 * @return \Illuminate\Database\Eloquent\Builder
4447 */
45- public static function whereConfig (Builder $ builder , string |array $ name , mixed $ value = null ): Builder
46- {
48+ public static function whereConfig (
49+ Builder $ builder ,
50+ string |array $ name ,
51+ string $ operator = null ,
52+ $ value = null ,
53+ string $ boolean = 'and '
54+ ): Builder {
4755 if (is_array ($ name )) {
4856 foreach ($ name as $ key => $ item ) {
49- static ::whereConfig ($ builder , $ key , $ item );
57+ if (is_array ($ item )) {
58+ static ::whereConfig ($ builder , ...$ item );
59+ } else {
60+ static ::whereConfig ($ builder , $ key , $ item );
61+ }
5062 }
5163
5264 return $ builder ;
5365 }
5466
55- return $ builder ->whereHas ('settings ' , static function (Builder $ builder ) use ($ name , $ value ): void {
56- $ builder
57- ->withoutGlobalScope (AddMetadata::class)
58- ->where (
59- static function (Builder $ builder ) use ($ name , $ value ): void {
60- $ builder
61- ->where ('value ' , $ value )
62- ->whereHas ('metadata ' , static function (Builder $ builder ) use ($ name ): void {
63- $ builder ->where ('name ' , $ name );
64- });
67+ return $ builder ->has (
68+ relation: 'settings ' ,
69+ boolean: $ boolean ,
70+ callback: static function (Builder $ builder ) use ($ name , $ operator , $ value ): void {
71+ $ builder
72+ ->withoutGlobalScope (AddMetadata::class)
73+ ->where (
74+ static function (Builder $ builder ) use ($ name , $ operator , $ value ): void {
75+ $ builder
76+ ->where ('value ' , $ operator , $ value )
77+ ->whereHas ('metadata ' , static function (Builder $ builder ) use ($ name ): void {
78+ $ builder ->where ('name ' , $ name );
79+ });
80+ });
6581 });
66- });
82+ }
83+
84+ /**
85+ * Filters the user by the config value.
86+ *
87+ * @param \Illuminate\Database\Eloquent\Builder $builder
88+ * @param string|array $name
89+ * @param string|null $operator
90+ * @param null $value
91+ *
92+ * @return \Illuminate\Database\Eloquent\Builder
93+ */
94+ public static function orWhereConfig (
95+ Builder $ builder ,
96+ string |array $ name ,
97+ string $ operator = null ,
98+ $ value = null ,
99+ ): Builder {
100+ return static ::whereConfig ($ builder , $ name , $ operator , $ value , 'or ' );
67101 }
68102}
0 commit comments