|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
use Spatie\MediaLibrary\HasMedia; |
|
8
|
|
|
use Spatie\MediaLibrary\InteractsWithMedia; |
|
9
|
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media; |
|
10
|
|
|
use Spatie\ModelStatus\HasStatuses; |
|
11
|
|
|
use Spatie\Sluggable\HasSlug; |
|
12
|
|
|
use Spatie\Sluggable\SlugOptions; |
|
13
|
|
|
use Spatie\Translatable\HasTranslations; |
|
14
|
|
|
|
|
15
|
|
|
class Testimonial extends Model implements HasMedia |
|
16
|
|
|
{ |
|
17
|
|
|
use HasFactory; |
|
18
|
|
|
use HasSlug; |
|
|
|
|
|
|
19
|
|
|
use HasTranslations; |
|
|
|
|
|
|
20
|
|
|
use HasStatuses; |
|
|
|
|
|
|
21
|
|
|
use InteractsWithMedia; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes that are mass assignable. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $fillable = [ |
|
29
|
|
|
'name', |
|
30
|
|
|
'surname', |
|
31
|
|
|
'profession', |
|
32
|
|
|
'feedback', |
|
33
|
|
|
'feedback_short', |
|
34
|
|
|
'photo', |
|
35
|
|
|
'personal_data_agreement', |
|
36
|
|
|
'publish_agreement', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The attributes that are translatable. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
public $translatable = ['profession', 'feedback', 'feedback_short']; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The parameters used in the index view search filters. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
public const SEARCH_PARAMETERS = [ |
|
52
|
|
|
'name', |
|
53
|
|
|
'surname', |
|
54
|
|
|
'countryId', |
|
55
|
|
|
'status' |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The possible values the publishing status can be. |
|
60
|
|
|
*/ |
|
61
|
|
|
const PUBLISHING_STATUS = [ |
|
62
|
|
|
'unpublished' => 'unpublished', |
|
63
|
|
|
'published' => 'published', |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Return the country of the teacher |
|
68
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
69
|
|
|
*/ |
|
70
|
|
|
public function country() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->belongsTo(Country::class); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Generates a unique slug. |
|
77
|
5 |
|
*/ |
|
78
|
|
|
public function getSlugOptions(): SlugOptions |
|
79
|
5 |
|
{ |
|
80
|
5 |
|
return SlugOptions::create() |
|
81
|
5 |
|
->generateSlugsFrom('author') |
|
82
|
|
|
->saveSlugsTo('slug'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Add Testimonial photo support using: |
|
87
|
|
|
* https://spatie.be/docs/laravel-medialibrary/v8/introduction |
|
88
|
|
|
* https://github.com/ebess/advanced-nova-media-library |
|
89
|
|
|
*/ |
|
90
|
|
|
public function registerMediaConversions(Media $media = null): void |
|
91
|
|
|
{ |
|
92
|
|
|
$this->addMediaConversion('thumb') |
|
93
|
|
|
->width(300) |
|
94
|
|
|
->height(300); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function registerMediaCollections(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->addMediaCollection('photo')->singleFile(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Testimonial full_name accessor. |
|
104
|
|
|
* $testimonial->full_name |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getFullNameAttribute() |
|
109
|
|
|
{ |
|
110
|
|
|
return "{$this->name} {$this->surname}"; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Return true if the post is published |
|
115
|
|
|
* |
|
116
|
|
|
* @return bool |
|
117
|
|
|
*/ |
|
118
|
|
|
public function isPublished(): bool |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->latestStatus('unpublished', 'published') == 'published'; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Return the post publishing status |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
1 |
|
*/ |
|
128
|
|
|
public function publishingStatus(): string |
|
129
|
1 |
|
{ |
|
130
|
|
|
return $this->latestStatus('unpublished', 'published'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|