File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Huntie \JsonApi \Tests \Fixtures \Models ;
4
+
5
+ class Comment extends Model
6
+ {
7
+ /**
8
+ * The user that created the comment.
9
+ *
10
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11
+ */
12
+ public function creator ()
13
+ {
14
+ return $ this ->belongsTo (User::class, 'creator_id ' );
15
+ }
16
+
17
+ /**
18
+ * The post the comment is made against.
19
+ *
20
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21
+ */
22
+ public function post ()
23
+ {
24
+ return $ this ->belongsTo (Post::class);
25
+ }
26
+
27
+ /**
28
+ * The parent comment, if this comment is a reply.
29
+ *
30
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
31
+ */
32
+ public function parent ()
33
+ {
34
+ return $ this ->belongsTo (Comment::class, 'parent_id ' );
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,16 @@ public function author()
14
14
return $ this ->belongsTo (User::class, 'author_id ' );
15
15
}
16
16
17
+ /**
18
+ * The comments made in reply to the post.
19
+ *
20
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
21
+ */
22
+ public function comments ()
23
+ {
24
+ return $ this ->hasMany (Comment::class);
25
+ }
26
+
17
27
/**
18
28
* The post tag memberships.
19
29
*
Original file line number Diff line number Diff line change @@ -16,8 +16,18 @@ class User extends Model
16
16
*
17
17
* @return \Illuminate\Database\Eloquent\Relations\HasMany
18
18
*/
19
- public function post ()
19
+ public function posts ()
20
20
{
21
21
return $ this ->hasMany (Post::class, 'author_id ' );
22
22
}
23
+
24
+ /**
25
+ * The post comments the user has created.
26
+ *
27
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
28
+ */
29
+ public function comments ()
30
+ {
31
+ return $ this ->hasMany (Comment::class, 'creator_id ' );
32
+ }
23
33
}
You can’t perform that action at this time.
0 commit comments