1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Foundation\Models\Base; |
4
|
|
|
|
5
|
|
|
use App\Foundation\Models\Traits\Draftable; |
6
|
|
|
use App\Foundation\Models\Traits\Presentable; |
7
|
|
|
use App\Foundation\Models\Traits\HasMedia as HasMediaTrait; |
8
|
|
|
use App\HasMeta\HasSeoValues; |
9
|
|
|
use Illuminate\Database\Eloquent\Model; |
10
|
|
|
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions; |
11
|
|
|
use Spatie\ModelCleanup\GetsCleanedUp; |
12
|
|
|
use Illuminate\Database\Eloquent\Builder; |
13
|
|
|
use Carbon\Carbon; |
14
|
|
|
use Spatie\Translatable\HasTranslations; |
15
|
|
|
|
16
|
|
|
abstract class ModuleModel extends Model implements HasMediaConversions, GetsCleanedUp |
17
|
|
|
{ |
18
|
|
|
use Draftable, Presentable, HasMediaTrait, HasSeoValues, HasTranslations; |
19
|
|
|
|
20
|
|
|
protected $guarded = ['id']; |
21
|
|
|
|
22
|
|
|
public function registerMediaConversions() |
23
|
|
|
{ |
24
|
|
|
$this->addMediaConversion('admin') |
25
|
|
|
->setWidth(368) |
26
|
|
|
->setHeight(232) |
27
|
|
|
->nonQueued(); |
28
|
|
|
|
29
|
|
|
$this->addMediaConversion('redactor') |
30
|
|
|
->setWidth(368) |
31
|
|
|
->setHeight(232) |
32
|
|
|
->nonQueued(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function cleanUp(Builder $query): Builder |
36
|
|
|
{ |
37
|
|
|
return $query |
38
|
|
|
->draft() |
39
|
|
|
->where('created_at', '<', Carbon::now()->subWeek()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function defaultSeoValues(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'title' => $this->name, |
|
|
|
|
46
|
|
|
'meta_title' => $this->name, |
|
|
|
|
47
|
|
|
'meta_description' => (string) string($this->text)->tease(155), |
|
|
|
|
48
|
|
|
'meta_og:title' => $this->name, |
|
|
|
|
49
|
|
|
'meta_og:type' => 'website', |
50
|
|
|
'meta_og:description' => (string) string($this->text)->tease(155), |
|
|
|
|
51
|
|
|
'meta_og:image' => $this->hasMedia('images') ? |
52
|
|
|
url($this->getFirstMediaUrl('images')) : |
53
|
|
|
url('/images/og-image.png'), |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.