@@ 91-109 (lines=19) @@ | ||
88 | } |
|
89 | } |
|
90 | ||
91 | public function scopeWhereState(Builder $builder, string $field, $states): Builder |
|
92 | { |
|
93 | self::getStateConfig(); |
|
94 | ||
95 | /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */ |
|
96 | $stateConfig = self::getStateConfig()[$field] ?? null; |
|
97 | ||
98 | if (! $stateConfig) { |
|
99 | throw InvalidConfig::unknownState($field, $this); |
|
100 | } |
|
101 | ||
102 | $abstractStateClass = $stateConfig->stateClass; |
|
103 | ||
104 | $stateNames = collect((array) $states)->map(function ($state) use ($abstractStateClass) { |
|
105 | return $abstractStateClass::resolveStateName($state); |
|
106 | }); |
|
107 | ||
108 | return $builder->whereIn($field, $stateNames); |
|
109 | } |
|
110 | ||
111 | public function scopeWhereNotState(Builder $builder, string $field, $states): Builder |
|
112 | { |
|
@@ 111-125 (lines=15) @@ | ||
108 | return $builder->whereIn($field, $stateNames); |
|
109 | } |
|
110 | ||
111 | public function scopeWhereNotState(Builder $builder, string $field, $states): Builder |
|
112 | { |
|
113 | /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */ |
|
114 | $stateConfig = self::getStateConfig()[$field] ?? null; |
|
115 | ||
116 | if (! $stateConfig) { |
|
117 | throw InvalidConfig::unknownState($field, $this); |
|
118 | } |
|
119 | ||
120 | $stateNames = collect((array) $states)->map(function ($state) use ($stateConfig) { |
|
121 | return $stateConfig->stateClass::resolveStateName($state); |
|
122 | }); |
|
123 | ||
124 | return $builder->whereNotIn($field, $stateNames); |
|
125 | } |
|
126 | ||
127 | /** |
|
128 | * @param \Spatie\ModelStates\State|string $state |