1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kurious7\SimplePages\Models; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Database\Eloquent\Builder; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
9
|
|
|
use Kurious7\SimplePages\Contracts\SimplePage as SimplePageContract; |
10
|
|
|
use Spatie\Sluggable\HasSlug; |
|
|
|
|
11
|
|
|
use Spatie\Sluggable\SlugOptions; |
12
|
|
|
|
13
|
|
|
class SimplePage extends Model implements SimplePageContract |
14
|
|
|
{ |
15
|
|
|
use HasSlug, |
16
|
|
|
SoftDeletes; |
17
|
|
|
|
18
|
|
|
protected $fillable = [ |
19
|
|
|
'title', |
20
|
|
|
'slug', |
21
|
|
|
'content', |
22
|
|
|
'show_in_menu', |
23
|
|
|
'public', |
24
|
|
|
'public_from', |
25
|
|
|
'public_until', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
protected $casts = [ |
29
|
|
|
'public' => 'boolean', |
30
|
|
|
'show_in_menu' => 'boolean', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
protected $dates = [ |
34
|
|
|
'public_from', |
35
|
|
|
'public_until', |
36
|
|
|
'created_at', |
37
|
|
|
'updated_at', |
38
|
|
|
'deleted_at', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
public function __construct(array $attributes = []) |
42
|
|
|
{ |
43
|
|
|
parent::__construct($attributes); |
44
|
|
|
|
45
|
|
|
$this->table = config('simple-pages.table', 'pages'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getSlugOptions() : SlugOptions |
49
|
|
|
{ |
50
|
|
|
return SlugOptions::create() |
51
|
|
|
->generateSlugsFrom('title') |
52
|
|
|
->saveSlugsTo('slug'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Attributes. |
57
|
|
|
*/ |
58
|
|
|
protected function getIsPublicAttribute() |
59
|
|
|
{ |
60
|
|
|
if ($this->public == 1 || |
|
|
|
|
61
|
|
|
($this->public_from && $this->public_from < new Carbon()) || |
|
|
|
|
62
|
|
|
($this->public_until && $this->public_until > new Carbon()) |
|
|
|
|
63
|
|
|
) { |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Scopes. |
72
|
|
|
*/ |
73
|
|
|
public function scopeVisibleInMenu($query): Builder |
74
|
|
|
{ |
75
|
|
|
return $query->where('show_in_menu', true); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function scopePublished($query): Builder |
79
|
|
|
{ |
80
|
|
|
return $query->where('public', true) |
81
|
|
|
->where(function ($query) { |
82
|
|
|
$today = (new Carbon)->toDateString(); |
83
|
|
|
|
84
|
|
|
$query->where(function ($query) use ($today) { |
85
|
|
|
$query->whereDate('public_from', '<=', $today)->orWhereNull('public_from'); |
86
|
|
|
}) |
87
|
|
|
->where(function ($query) use ($today) { |
88
|
|
|
$query->whereDate('public_until', '>=', $today)->orWhereNull('public_until'); |
89
|
|
|
}); |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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