File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace DavidWesdijk \LaravelPolymorphicEav \Scopes ;
4+
5+ use DavidWesdijk \LaravelPolymorphicEav \EntityAttribute ;
6+ use Illuminate \Database \Eloquent \Builder ;
7+
8+ /**
9+ * Trait EntityAttributeValueScopes
10+ * @package DavidWesdijk\LaravelPolymorphicEav\Scopes
11+ *
12+ * @method static hasAttribute(EntityAttribute|int $attribute) Get instances with a given attribute
13+ */
14+ trait EntityAttributeValueScopes
15+ {
16+ /**
17+ * Get instances with a given attribute
18+ *
19+ * @param Builder $query
20+ * @param $attribute
21+ *
22+ * @return Builder
23+ */
24+ public function scopeHasAttribute (Builder $ query , $ attribute ): Builder
25+ {
26+ $ attributeId = ($ attribute instanceof EntityAttribute) ? $ attribute ->id : $ attribute ;
27+
28+ return $ query ->whereHas (static ::$ relationName , function (Builder $ query ) use ($ attributeId ) {
29+ $ query ->where ('entity_attribute_id ' , $ attributeId );
30+ });
31+ }
32+ }
Original file line number Diff line number Diff line change 44
55use DavidWesdijk \LaravelPolymorphicEav \EntityAttributeValue ;
66use DavidWesdijk \LaravelPolymorphicEav \Resolvers \GroupResolver ;
7+ use DavidWesdijk \LaravelPolymorphicEav \Scopes \EntityAttributeValueScopes ;
78
9+ /**
10+ * Trait HasEntityAttributeValues
11+ * @package DavidWesdijk\LaravelPolymorphicEav\Traits
12+ */
813trait HasEntityAttributeValues
914{
15+ use EntityAttributeValueScopes;
16+
1017 /**
1118 * @var string
1219 */
You can’t perform that action at this time.
0 commit comments