PHP Class app\repositories\PostRepository

Show file Open project: forehalo/materialize-blog Class Usage Examples

Protected Properties

Property Type Description
$category Category Model
$model Post Model
$tag Tag Model

Public Methods

Method Description
__construct ( Post $post, Category $category, Tag $tag ) BlogRepository constructor.
all ( integer $n = null, boolean $published = true ) : mixed Get all posts.
body ( $id ) : mixed Get post body.
destroy ( $id ) Destroy a post.
doFavorite ( $id ) Update favorite count
getByColumn ( string $value, string $column = 'id' ) Get post by given column.
parseCategory ( $name ) : mixed Get or create new category and return category id.
parseOrigin ( $origin ) : string Parse Markdown.
search ( $key, integer $pagination = 10 ) : mixed Search in all published posts.
store ( $inputs ) Store new post in database.
update ( $inputs, $id ) Update a post.
updatePublish ( $input, $id ) Update post published status

Private Methods

Method Description
savePost ( $post, $inputs ) Store post information in database.
syncTags ( $post, string $tags ) Synchronize post tags relation.

Method Details

__construct() public method

BlogRepository constructor.
public __construct ( Post $post, Category $category, Tag $tag )
$post app\models\Post
$category app\models\Category
$tag app\models\Tag

all() public method

Get all posts.
public all ( integer $n = null, boolean $published = true ) : mixed
$n integer pagination
$published boolean whether fetch unpublished posts.
return mixed

body() public method

Get post body.
public body ( $id ) : mixed
$id
return mixed

destroy() public method

Destroy a post.
public destroy ( $id )
$id

doFavorite() public method

Update favorite count
public doFavorite ( $id )
$id

getByColumn() public method

Get post by given column.
public getByColumn ( string $value, string $column = 'id' )
$value string column value.
$column string column name, default={id}

parseCategory() public method

Get or create new category and return category id.
public parseCategory ( $name ) : mixed
$name category name
return mixed category id

parseOrigin() public method

Parse Markdown.
public parseOrigin ( $origin ) : string
$origin
return string HTML content

store() public method

Store new post in database.
public store ( $inputs )
$inputs

update() public method

Update a post.
public update ( $inputs, $id )
$inputs
$id post id

updatePublish() public method

Update post published status
public updatePublish ( $input, $id )
$input
$id

Property Details

$category protected property

Category Model
protected $category

$model protected property

Post Model
protected $model

$tag protected property

Tag Model
protected $tag