File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 88use Illuminate \Database \Eloquent \Factories \HasFactory ;
99use Illuminate \Database \Eloquent \Model ;
1010use Illuminate \Database \Eloquent \Relations \BelongsTo ;
11+ use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
1112use Illuminate \Database \Eloquent \Relations \HasMany ;
1213
1314/**
@@ -81,4 +82,28 @@ public function comments(): HasMany
8182 {
8283 return $ this ->hasMany (Comment::class);
8384 }
85+
86+ /**
87+ * @return BelongsToMany<Category,Article>
88+ */
89+ public function categories (): BelongsToMany
90+ {
91+ return $ this ->belongsToMany (Category::class, 'article_categories ' );
92+ }
93+
94+ /**
95+ * @return BelongsToMany<Tag,Article>
96+ */
97+ public function tags (): BelongsToMany
98+ {
99+ return $ this ->belongsToMany (Tag::class, 'article_tags ' );
100+ }
101+
102+ /**
103+ * @return BelongsToMany<User,Article>
104+ */
105+ public function authors (): BelongsToMany
106+ {
107+ return $ this ->belongsToMany (User::class, 'article_authors ' )->withPivot ('role ' );
108+ }
84109}
Original file line number Diff line number Diff line change 66
77use Illuminate \Database \Eloquent \Factories \HasFactory ;
88use Illuminate \Database \Eloquent \Model ;
9- use Illuminate \Database \Eloquent \Relations \HasMany ;
9+ use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
1010
1111/**
1212 * @property int $id
@@ -34,10 +34,10 @@ protected function casts(): array
3434 }
3535
3636 /**
37- * @return HasMany<ArticleCategory ,Category>
37+ * @return BelongsToMany<Article ,Category>
3838 */
39- public function articles (): HasMany
39+ public function articles (): BelongsToMany
4040 {
41- return $ this ->hasMany (ArticleCategory ::class);
41+ return $ this ->belongsToMany (Article ::class, ' article_categories ' );
4242 }
4343}
Original file line number Diff line number Diff line change 66
77use Illuminate \Database \Eloquent \Factories \HasFactory ;
88use Illuminate \Database \Eloquent \Model ;
9+ use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
910
1011/**
1112 * @property int $id
@@ -33,4 +34,12 @@ protected function casts(): array
3334 {
3435 return [];
3536 }
37+
38+ /**
39+ * @return BelongsToMany<Article,Tag>
40+ */
41+ public function articles (): BelongsToMany
42+ {
43+ return $ this ->belongsToMany (Article::class, 'article_tags ' );
44+ }
3645}
You can’t perform that action at this time.
0 commit comments