forked from ericlbarnes/wardrobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.php
82 lines (70 loc) · 1.46 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php namespace Wardrobe;
use Config, Cache;
use Carbon\Carbon;
class Post extends \Eloquent {
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'posts';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = array('title', 'slug', 'content', 'active', 'publish_date', 'user_id');
/**
* Tags Relationship
*
* @return Relationship
*/
public function tags()
{
return $this->hasMany('\Wardrobe\Tag', 'post_id');
}
/**
* User relationship
*
* @return Relationship
*/
public function user()
{
return $this->belongsTo('Wardrobe\User');
}
/**
* Get the content parsed into html
*
* @return string
*/
public function getParsedContentAttribute()
{
if (Config::get('wardrobe.cache'))
{
$content = $this->attributes['content'];
return Cache::rememberForever('post-'.$this->attributes['id'], function() use ($content)
{
return md($content);
});
}
return md($this->attributes['content']);
}
/**
* Get the atom date for atom feeds
* @return DateTime
*/
public function getAtomDateAttribute()
{
$dt = Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['publish_date']);
return $dt->toATOMString();
}
/**
* Get the atom date for rss feeds
* @return DateTime
*/
public function getRssDateAttribute()
{
$dt = Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['publish_date']);
return $dt->toRSSString();
}
}