🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-10-03 12:10:00.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-10-03 12:10:00.0 +00:00:00
commit
ba95ff711cf24ccaddb2c917c3af07d5c10d07f0 [patch]
tree
d01aecfc123cb419934aadebb62c048ecc9f7347
parent
3515c6afaf9ca354f28a4b07143e9a7eaf78ef9b
download
ba95ff711cf24ccaddb2c917c3af07d5c10d07f0.tar.gz

Eloquent methods for getting posts by type



Diff

 src/Models/Post.php | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/Models/Post.php b/src/Models/Post.php
index a1ac8f9..c33ecc2 100644
--- a/src/Models/Post.php
+++ b/src/Models/Post.php
@@ -1,6 +1,7 @@
<?php
namespace Koselig\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -16,6 +17,29 @@ class Post extends Model
    public $primaryKey = 'ID';

    /**
     * Get all the posts within a certain post type.
     *
     * @param Builder $query query to add the scope to
     * @param string $name name of the post type
     * @return Builder
     */
    public function scopePostType($query, $name)
    {
        return $query->where('post_type', $name);
    }

    /**
     * Get all the posts which are published.
     *
     * @param Builder $query query to add the scope to
     * @return Builder
     */
    public function scopePublished($query)
    {
        return $query->where('post_status', 'publish');
    }

    /**
     * Get all the meta values that belong to this post.
     *
     * @return HasMany