🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-10-16 22:30:54.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-10-16 22:30:54.0 +00:00:00
commit
b7a2f96cb2475df797f5c9fa78a0d360c836d6ac [patch]
tree
158447c5dcf28aa2e7f245d3e2c6cf40783d37db
parent
d4e4cba2073f99be617321d0636e790d9dbda668
download
b7a2f96cb2475df797f5c9fa78a0d360c836d6ac.tar.gz

comment support



Diff

 src/Models/Comment.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/Models/Post.php    | 10 +++++++++-
 2 files changed, 64 insertions(+)

diff --git a/src/Models/Comment.php b/src/Models/Comment.php
new file mode 100644
index 0000000..1dff841
--- /dev/null
+++ b/src/Models/Comment.php
@@ -0,0 +1,54 @@
<?php
namespace Koselig\Models;

use Illuminate\Database\Eloquent\Model;
use Koselig\Support\Wordpress;

/**
 * Table containing all the comments belonging to posts.
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class Comment extends Model
{
    protected $table = DB_PREFIX . 'comments';
    protected $primaryKey = 'comment_ID';
    protected $dates = ['comment_date', 'comment_date_gmt'];
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     * @return void
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        // Set the current table to the site's own table if we're in a multisite
        if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) {
            $this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_comments');
        }
    }

    /**
     * Get the post that this comment belongs to.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function post()
    {
        return $this->belongsTo(Post::class, 'comment_post_ID');
    }

    /**
     * Get the user that posted this comment.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
diff --git a/src/Models/Post.php b/src/Models/Post.php
index c24e1a5..314a4ac 100644
--- a/src/Models/Post.php
+++ b/src/Models/Post.php
@@ -86,6 +86,16 @@ class Post extends Model
    }

    /**
     * Get all the comments that belong to this post.
     *
     * @return HasMany
     */
    public function comments()
    {
        return $this->hasMany(Comment::class, 'comment_post_ID');
    }

    /**
     * Get meta values for this Post.
     *
     * @param array|string|null $key