Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user can view comment in single post
comment has creator and created date
- Loading branch information
1 parent
70a70bc
commit 8672c19
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,8 @@ | |
|
||
class Comment extends Model | ||
{ | ||
// | ||
public function creator(){ | ||
return $this->BelongsTo(User::class,'user_id'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,8 @@ | |
|
||
class Post extends Model | ||
{ | ||
// | ||
public function comment(){ | ||
return $this->hasMany(Comment::class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
class CommentTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function test_comment_should_has_creator() | ||
{ | ||
// Giving comment object | ||
$comment = factory('App\Comment')->create(); | ||
// should include User object | ||
$this->assertInstanceOf('App\User',$comment->creator); // I expect creator function has User instance | ||
} | ||
} |