Skip to content

Commit 8ef33eb

Browse files
committed
Add example Comment model for tests
1 parent 5705bce commit 8ef33eb

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

tests/Fixtures/Models/Comment.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

tests/Fixtures/Models/Post.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public function author()
1414
return $this->belongsTo(User::class, 'author_id');
1515
}
1616

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+
1727
/**
1828
* The post tag memberships.
1929
*

tests/Fixtures/Models/User.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ class User extends Model
1616
*
1717
* @return \Illuminate\Database\Eloquent\Relations\HasMany
1818
*/
19-
public function post()
19+
public function posts()
2020
{
2121
return $this->hasMany(Post::class, 'author_id');
2222
}
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+
}
2333
}

0 commit comments

Comments
 (0)