Skip to content

Commit

Permalink
Merge pull request #8 from HAEDev/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
LNCH authored Apr 16, 2019
2 parents fc52ad0 + 2e7e3e5 commit 8458dd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"licence": "MIT",
"minimum-stability": "dev",
"require": {
"doctrine/dbal": "^2.7"
"doctrine/dbal": "^2.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function postComment(BlogPost $post, Request $request)
'name' => 'sometimes|string|max:200',
'email' => 'sometimes|email|max:150',
'comment' => 'required|string|max:65000',
'parent_id' => 'sometimes|integer|in:'.implode(",", $post->comments()->pluck("id")->toArray()),
'parent_id' => 'sometimes',
]);

$post->comments()->create([
Expand Down
25 changes: 23 additions & 2 deletions src/Models/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,26 @@ public function featuredImage()
*
* @return array|\Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
public function allComments()
{
return config("laravel-blog.comments.enabled")
? $this->hasMany(Comment::class, "post_id", "id")
->where("parent_id", null)
->orderby("created_at", "desc")
: [];
}

/**
* Retrieves all top level comments, without replies
*
* @return array|\Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return config("laravel-blog.comments.enabled")
? $this->allComments()->where("parent_id", null)
: [];
}

/**
* Returns an array of available statuses a BlogPost can be in.
*
Expand Down Expand Up @@ -249,6 +260,16 @@ public function getAuthorUrlAttribute()
return url("blog/author/{$this->author->id}-" . strtolower(str_replace(" ", "-", $this->author->name)));
}

/**
* Returns the amount of comments made on this blog post
*
* @return int
*/
public function getCommentsCountAttribute()
{
return count($this->allComments);
}

public function isWithinDays($days = 7)
{
$date = strtotime("-$days days");
Expand Down
5 changes: 4 additions & 1 deletion src/Views/frontend/partials/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

<div class="post-meta">
Posted on {{ $post->published_at->format("jS F, Y") }} at {{ $post->published_at->format("H:i") }}
@if (config("laravel-blog.comments.enabled") && $post->commentsCount)
- {{ $post->commentsCount }} comments
@endif
</div>
</header>

Expand All @@ -28,4 +31,4 @@

</div> <!-- End .post-details -->

</article>
</article>

0 comments on commit 8458dd1

Please sign in to comment.