|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wingsline\Blog\Posts; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
use Illuminate\Support\Facades\Auth; |
|
8
|
|
|
use Spatie\Feed\Feedable; |
|
9
|
|
|
use Spatie\Feed\FeedItem; |
|
10
|
|
|
use Spatie\MediaLibrary\HasMedia; |
|
11
|
|
|
use Spatie\MediaLibrary\InteractsWithMedia; |
|
12
|
|
|
use Spatie\Sluggable\HasSlug; |
|
|
|
|
|
|
13
|
|
|
use Spatie\Sluggable\SlugOptions; |
|
14
|
|
|
use Spatie\Tags\HasTags; |
|
15
|
|
|
use Wingsline\Blog\Markdown\Markdown; |
|
16
|
|
|
|
|
17
|
|
|
class Post extends Model implements Feedable, HasMedia |
|
18
|
|
|
{ |
|
19
|
|
|
use HasSlug; |
|
20
|
|
|
use HasTags; |
|
21
|
|
|
use InteractsWithMedia; |
|
22
|
|
|
use PostPresenter; |
|
23
|
|
|
|
|
24
|
|
|
public $casts = [ |
|
25
|
|
|
'text' => '', |
|
26
|
|
|
'published' => 'boolean', |
|
27
|
|
|
'original_content' => 'boolean', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public $dates = ['publish_date']; |
|
31
|
|
|
public $with = ['tags']; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The table associated with the model. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $table = 'posts'; |
|
39
|
|
|
|
|
40
|
|
|
public static function getFeedItems() |
|
41
|
|
|
{ |
|
42
|
|
|
return static::published() |
|
43
|
|
|
->public() |
|
44
|
|
|
->orderBy('publish_date', 'desc') |
|
45
|
|
|
->limit(100) |
|
46
|
|
|
->get(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Markdown accessor. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getMarkdownAttribute() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->getRawOriginal('text'); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Slug options. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getSlugOptions(): SlugOptions |
|
63
|
|
|
{ |
|
64
|
|
|
return SlugOptions::create() |
|
65
|
|
|
->generateSlugsFrom('title') |
|
66
|
|
|
->saveSlugsTo('slug'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Text accessor. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $original |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getTextAttribute($original) |
|
77
|
|
|
{ |
|
78
|
|
|
return Markdown::convertWithParser($original); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function scopePublic(Builder $query) |
|
82
|
|
|
{ |
|
83
|
|
|
$query->where('publish_date', '<=', now()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function scopePublished(Builder $query) |
|
87
|
|
|
{ |
|
88
|
|
|
$query->where('published', true); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return array|\Spatie\Feed\FeedItem |
|
93
|
|
|
*/ |
|
94
|
|
|
public function toFeedItem() |
|
95
|
|
|
{ |
|
96
|
|
|
return FeedItem::create() |
|
97
|
|
|
->id($this->id) |
|
98
|
|
|
->title($this->formatted_title) |
|
|
|
|
|
|
99
|
|
|
->summary($this->text) |
|
100
|
|
|
->updated($this->publish_date) |
|
101
|
|
|
->link($this->url) |
|
|
|
|
|
|
102
|
|
|
->author($this->author); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Update model attributes from the form. |
|
107
|
|
|
* |
|
108
|
|
|
* @return static |
|
109
|
|
|
*/ |
|
110
|
|
|
public function updateAttributes(array $attributes) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->title = $attributes['title']; |
|
|
|
|
|
|
113
|
|
|
$this->text = $attributes['text']; |
|
|
|
|
|
|
114
|
|
|
$this->publish_date = $attributes['publish_date']; |
|
|
|
|
|
|
115
|
|
|
$this->published = $attributes['published'] ?? false; |
|
|
|
|
|
|
116
|
|
|
$this->original_content = $attributes['original_content'] ?? false; |
|
|
|
|
|
|
117
|
|
|
$this->external_url = $attributes['external_url']; |
|
|
|
|
|
|
118
|
|
|
$this->author = Auth::user()->name; |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
$this->save(); |
|
121
|
|
|
|
|
122
|
|
|
if ($attributes['tags_text']) { |
|
123
|
|
|
$tags = array_map(function (string $tag) { |
|
124
|
|
|
return trim(strtolower($tag)); |
|
125
|
|
|
}, explode(',', $attributes['tags_text'])); |
|
126
|
|
|
|
|
127
|
|
|
$this->syncTags($tags); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths