Skip to content

Commit b083b15

Browse files
committed
Add additional example models for tests
1 parent edc2eed commit b083b15

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

tests/Fixtures/Models/Post.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Huntie\JsonApi\Tests\Fixtures\Models;
4+
5+
class Post extends Model
6+
{
7+
/**
8+
* The author of the post.
9+
*
10+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11+
*/
12+
public function author()
13+
{
14+
return $this->belongsTo(User::class, 'author_id');
15+
}
16+
17+
/**
18+
* The post tag memberships.
19+
*
20+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
21+
*/
22+
public function tags()
23+
{
24+
return $this->belongsToMany(Tag::class);
25+
}
26+
}

tests/Fixtures/Models/Tag.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Huntie\JsonApi\Tests\Fixtures\Models;
4+
5+
class Tag extends Model
6+
{
7+
/**
8+
* The posts matching the tag.
9+
*
10+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
11+
*/
12+
public function posts()
13+
{
14+
return $this->belongsToMany(Post::class);
15+
}
16+
}

tests/Fixtures/Models/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ class User extends Model
1010
* @var array
1111
*/
1212
protected $hidden = ['password'];
13+
14+
/**
15+
* The posts the user has authored.
16+
*
17+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
18+
*/
19+
public function post()
20+
{
21+
return $this->hasMany(Post::class, 'author_id');
22+
}
1323
}

0 commit comments

Comments
 (0)