PHP Class Corcel\Post

Inheritance: extends Illuminate\Database\Eloquent\Model
显示文件 Open project: jgrossi/corcel Class Usage Examples

Protected Properties

Property Type Description
$appends array The accessors to append to the model's array form.
$dates
$fillable
$postTypes array
$primaryKey
$shortcodes
$table
$with

Public Methods

Method Description
__construct ( array $attributes = [] )
__get ( string $key ) : string Magic method to return the meta data like the post original fields.
addShortcode ( string $tag, function $function ) Add a shortcode handler
attachment ( ) : Illuminate\Database\Eloquent\Collection Get attachment.
author ( ) : Illuminate\Database\Eloquent\Collection Author relationship.
clearRegisteredPostTypes ( ) Clears any registered post types
comments ( ) : Illuminate\Database\Eloquent\Collection Comments relationship.
fields ( )
getAcfAttribute ( ) : Corcel\Acf\AdvancedCustomFields
getAuthorIdAttribute ( ) : integer Gets the author id attribute.
getContentAttribute ( ) : string Gets the content attribute.
getCreatedAtAttribute ( ) : date Gets the created at attribute.
getExcerptAttribute ( ) : string Gets the excerpt attribute.
getFormat ( ) : boolean | string Get the post format, like the WP get_post_format() function
getImageAttribute ( ) : string Gets the featured image if any Looks in meta the _thumbnail_id field.
getKeywordsAttribute ( ) : array Gets the keywords as array.
getKeywordsStrAttribute ( ) : string Gets the keywords as string.
getMainCategoryAttribute ( ) : string Gets the first term of the first taxonomy found.
getMimeTypeAttribute ( ) : string Gets the mime type attribute.
getParentIdAttribute ( ) : integer Gets the parent id attribute.
getSlugAttribute ( ) : string Gets the slug attribute.
getStatusAttribute ( ) : string Gets the status attribute.
getTermsAttribute ( ) : array Gets all the terms arranged taxonomy => terms[].
getTitleAttribute ( ) : string Gets the title attribute.
getTypeAttribute ( ) : string Gets the type attribute.
getUpdatedAtAttribute ( ) : date Gets the updated at attribute.
getUrlAttribute ( ) : string Gets the url attribute.
hasTerm ( string $taxonomy, string $term ) : boolean Whether the post contains the term or not.
meta ( ) : Corcel\PostMetaCollection Meta data relationship.
newFromBuilder ( array $attributes = [], null $connection = null ) : mixed Overrides default behaviour by instantiating class based on the $attributes->post_type value
newQuery ( boolean $excludeDeleted = true ) : Corcel\PostBuilder Overriding newQuery() to the custom PostBuilder with some interesting methods.
parent ( ) : Corcel\Post Parent post.
registerPostType ( string $name, string $class ) Register your Post Type classes here to have them be instantiated instead of the standard Post model
removeShortcode ( string $tag ) Removes a shortcode handler
revision ( ) : Illuminate\Database\Eloquent\Collection Get revisions from post.
save ( array $options = [] )
scopeHasMeta ( $query, $meta, null $value = null ) : Illuminate\Database\Eloquent\Collection Meta filter scope.
stripShortcodes ( string $content ) : string Process the shortcodes
taxonomies ( ) : Illuminate\Database\Eloquent\Collection Taxonomy relationship.
thumbnail ( ) Return the post thumbnail

Method Details

__construct() public method

public __construct ( array $attributes = [] )
$attributes array

__get() public method

Magic method to return the meta data like the post original fields.
public __get ( string $key ) : string
$key string
return string

addShortcode() public static method

Add a shortcode handler
public static addShortcode ( string $tag, function $function )
$tag string the shortcode tag
$function function the shortcode handling function

attachment() public method

Get attachment.
public attachment ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

author() public method

Author relationship.
public author ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

clearRegisteredPostTypes() public static method

Clears any registered post types
public static clearRegisteredPostTypes ( )

comments() public method

Comments relationship.
public comments ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

fields() public method

public fields ( )

getAcfAttribute() public method

public getAcfAttribute ( ) : Corcel\Acf\AdvancedCustomFields
return Corcel\Acf\AdvancedCustomFields

getAuthorIdAttribute() public method

Gets the author id attribute.
public getAuthorIdAttribute ( ) : integer
return integer

getContentAttribute() public method

Gets the content attribute.
public getContentAttribute ( ) : string
return string

getCreatedAtAttribute() public method

Gets the created at attribute.
public getCreatedAtAttribute ( ) : date
return date

getExcerptAttribute() public method

Gets the excerpt attribute.
public getExcerptAttribute ( ) : string
return string

getFormat() public method

Get the post format, like the WP get_post_format() function
public getFormat ( ) : boolean | string
return boolean | string

getImageAttribute() public method

Gets the featured image if any Looks in meta the _thumbnail_id field.
public getImageAttribute ( ) : string
return string

getKeywordsAttribute() public method

Gets the keywords as array.
public getKeywordsAttribute ( ) : array
return array

getKeywordsStrAttribute() public method

Gets the keywords as string.
public getKeywordsStrAttribute ( ) : string
return string

getMainCategoryAttribute() public method

Gets the first term of the first taxonomy found.
public getMainCategoryAttribute ( ) : string
return string

getMimeTypeAttribute() public method

Gets the mime type attribute.
public getMimeTypeAttribute ( ) : string
return string

getParentIdAttribute() public method

Gets the parent id attribute.
public getParentIdAttribute ( ) : integer
return integer

getSlugAttribute() public method

Gets the slug attribute.
public getSlugAttribute ( ) : string
return string

getStatusAttribute() public method

Gets the status attribute.
public getStatusAttribute ( ) : string
return string

getTermsAttribute() public method

Gets all the terms arranged taxonomy => terms[].
public getTermsAttribute ( ) : array
return array

getTitleAttribute() public method

Gets the title attribute.
public getTitleAttribute ( ) : string
return string

getTypeAttribute() public method

Gets the type attribute.
public getTypeAttribute ( ) : string
return string

getUpdatedAtAttribute() public method

Gets the updated at attribute.
public getUpdatedAtAttribute ( ) : date
return date

getUrlAttribute() public method

Gets the url attribute.
public getUrlAttribute ( ) : string
return string

hasTerm() public method

Whether the post contains the term or not.
public hasTerm ( string $taxonomy, string $term ) : boolean
$taxonomy string
$term string
return boolean

meta() public method

Meta data relationship.
public meta ( ) : Corcel\PostMetaCollection
return Corcel\PostMetaCollection

newFromBuilder() public method

By default, this method will always return an instance of the calling class. However if post types have been registered with the Post class using the registerPostType() static method, this will now return an instance of that class instead. If the post type string from $attributes->post_type does not appear in the static $postTypes array, then the class instantiated will be the called class (the default behaviour of this method).
public newFromBuilder ( array $attributes = [], null $connection = null ) : mixed
$attributes array
$connection null
return mixed

newQuery() public method

Overriding newQuery() to the custom PostBuilder with some interesting methods.
public newQuery ( boolean $excludeDeleted = true ) : Corcel\PostBuilder
$excludeDeleted boolean
return Corcel\PostBuilder

parent() public method

Parent post.
public parent ( ) : Corcel\Post
return Corcel\Post

registerPostType() public static method

This method allows you to register classes that will be used for specific post types as defined in the post_type column of the wp_posts table. If a post type is registered here, when a Post object is returned from the posts table it will be automatically converted into the appropriate class for its post type. If you register a Page class for the post_type 'page', then whenever a Post is fetched from the database that has its post_type has 'page', it will be returned as a Page instance, instead of the default and generic Post instance.
public static registerPostType ( string $name, string $class )
$name string The name of the post type (e.g. 'post', 'page', 'custom_post_type')
$class string The class that represents the post type model (e.g. 'Post', 'Page', 'CustomPostType')

removeShortcode() public static method

Removes a shortcode handler
public static removeShortcode ( string $tag )
$tag string the shortcode tag

revision() public method

Get revisions from post.
public revision ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

save() public method

public save ( array $options = [] )
$options array

scopeHasMeta() public method

Meta filter scope.
public scopeHasMeta ( $query, $meta, null $value = null ) : Illuminate\Database\Eloquent\Collection
$query
$meta
$value null
return Illuminate\Database\Eloquent\Collection

stripShortcodes() public method

Process the shortcodes
public stripShortcodes ( string $content ) : string
$content string the content
return string

taxonomies() public method

Taxonomy relationship.
public taxonomies ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

thumbnail() public method

Return the post thumbnail
public thumbnail ( )

Property Details

$appends protected_oe property

The accessors to append to the model's array form.
protected array $appends
return array

$dates protected_oe property

protected $dates

$fillable protected_oe property

protected $fillable

$postTypes protected_oe static_oe property

protected static array $postTypes
return array

$primaryKey protected_oe property

protected $primaryKey

$shortcodes protected_oe static_oe property

protected static $shortcodes

$table protected_oe property

protected $table

$with protected_oe property

protected $with