22
33namespace TypiCMS \Modules \Objects \Models ;
44
5- use Dimsav \Translatable \Translatable ;
65use Laracasts \Presenter \PresentableTrait ;
6+ use Spatie \Translatable \HasTranslations ;
77use TypiCMS \Modules \Core \Models \Base ;
8+ use TypiCMS \Modules \Files \Models \File ;
89use TypiCMS \Modules \History \Traits \Historable ;
10+ use TypiCMS \Modules \Objects \Presenters \ModulePresenter ;
911
1012class Object extends Base
1113{
14+ use HasTranslations;
1215 use Historable;
1316 use PresentableTrait;
14- use Translatable;
1517
16- protected $ presenter = ' TypiCMS\Modules\Objects\Presenters\ ModulePresenter' ;
18+ protected $ presenter = ModulePresenter::class ;
1719
18- /**
19- * Declare any properties that should be hidden from JSON Serialization.
20- *
21- * @var array
22- */
23- protected $ hidden = [];
20+ protected $ guarded = ['id ' , 'exit ' ];
2421
25- protected $ fillable = [
26- 'image ' ,
27- ];
28-
29- /**
30- * Translatable model configs.
31- *
32- * @var array
33- */
34- public $ translatedAttributes = [
22+ public $ translatable = [
3523 'title ' ,
3624 'slug ' ,
3725 'status ' ,
3826 'summary ' ,
3927 'body ' ,
4028 ];
4129
42- protected $ appends = ['status ' , 'title ' , 'thumb ' ];
30+ protected $ appends = ['image ' , 'thumb ' , 'title_translated ' , ' status_translated ' ];
4331
4432 /**
45- * Columns that are file .
33+ * Append title_translated attribute .
4634 *
47- * @var array
35+ * @return string
4836 */
49- public $ attachments = [
50- 'image ' ,
51- ];
37+ public function getTitleTranslatedAttribute ()
38+ {
39+ $ locale = config ('app.locale ' );
40+
41+ return $ this ->translate ('title ' , config ('typicms.content_locale ' , $ locale ));
42+ }
5243
5344 /**
54- * Append status attribute from translation table .
45+ * Append status_translated attribute.
5546 *
5647 * @return string
5748 */
58- public function getStatusAttribute ( $ value )
49+ public function getStatusTranslatedAttribute ( )
5950 {
60- return $ value ;
51+ $ locale = config ('app.locale ' );
52+
53+ return $ this ->translate ('status ' , config ('typicms.content_locale ' , $ locale ));
6154 }
6255
6356 /**
64- * Append title attribute from translation table .
57+ * Append image attribute.
6558 *
66- * @return string title
59+ * @return string
6760 */
68- public function getTitleAttribute ( $ value )
61+ public function getImageAttribute ( )
6962 {
70- return $ value ;
63+ return $ this -> files -> first () ;
7164 }
7265
7366 /**
@@ -79,4 +72,15 @@ public function getThumbAttribute()
7972 {
8073 return $ this ->present ()->thumbSrc (null , 22 );
8174 }
75+
76+ /**
77+ * Has many files.
78+ *
79+ * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
80+ */
81+ public function files ()
82+ {
83+ return $ this ->morphToMany (File::class, 'model ' , 'model_has_files ' , 'model_id ' , 'file_id ' )
84+ ->orderBy ('model_has_files.position ' );
85+ }
8286}
0 commit comments