22
33namespace Javaabu \Cms \Models ;
44
5- use Illuminate \Database \Eloquent \Relations \ BelongsTo ;
5+ use Illuminate \Database \Eloquent \Factories \ HasFactory ;
66use Illuminate \Database \Eloquent \Relations \HasMany ;
7- use Illuminate \Support \Str ;
8- use Javaabu \Cms \Enums \PostTypeFeatures ;
7+ use Javaabu \Cms \Database \Factories \PostTypeFactory ;
98use Javaabu \Helpers \AdminModel \AdminModel ;
109use Javaabu \Helpers \AdminModel \IsAdminModel ;
1110use Illuminate \Database \Eloquent \Model ;
1413
1514class PostType extends Model implements AdminModel, Translatable
1615{
17- // use HasFactory;
16+ use HasFactory;
1817 use IsAdminModel;
1918 use IsJsonTranslatable;
2019 /**
@@ -47,20 +46,10 @@ public function getAdminUrlAttribute(): string
4746 return 'post_type ' ;
4847 }
4948
50- /**
51- * Get the permission slug
52- *
53- * @return string
54- */
55- public function getPermissionSlugAttribute ()
56- {
57- return Str::slug ($ this ->slug , '_ ' );
58- }
59-
6049 /**
6150 * Get the route key name
6251 */
63- public function getRouteKeyName ()
52+ public function getRouteKeyName (): string
6453 {
6554 return 'slug ' ;
6655 }
@@ -78,44 +67,11 @@ public function getTranslatables(): array
7867 ];
7968 }
8069
81- public function categoryType (): BelongsTo
82- {
83- return $ this ->belongsTo (CategoryType::class);
84- }
85-
86- public function getFeatureName ($ feature ): ?string
87- {
88- if (! $ this ->hasFeature ($ feature )) {
89- return null ;
90- }
91-
92- $ feature_title = $ this ->features [$ feature ];
93-
94- if (gettype ($ feature_title ) == 'boolean ' ) {
95- return PostTypeFeatures::getLabel ($ feature );
96- }
97-
98- if (gettype ($ feature_title ) == 'string ' ) {
99- return Str::title ($ feature_title );
100- }
101-
102- return null ;
103- }
104-
10570 public function hasFeature ($ feature ): bool
10671 {
10772 return array_key_exists ($ feature , $ this ->features );
10873 }
10974
110- public function getFeatureCollectionName ($ feature ): ?string
111- {
112- if (! $ this ->hasFeature ($ feature )) {
113- return null ;
114- }
115-
116- return PostTypeFeatures::getCollectionName ($ feature );
117- }
118-
11975 /**
12076 * Gets the views to use for the post type
12177 *
@@ -138,14 +94,6 @@ public function getPaginatorCount(): int
13894 return get_setting ($ this ->slug . '_per_page ' ) ?? get_setting ('per_page ' );
13995 }
14096
141- /**
142- * A post type has many posts
143- */
144- public function userVisiblePosts ()
145- {
146- return $ this ->posts ()->userVisibleForPostType ($ this );
147- }
148-
14997 /**
15098 * A post type has many posts
15199 *
@@ -156,14 +104,9 @@ public function posts(): HasMany
156104 return $ this ->hasMany (Post::class, 'type ' , 'slug ' );
157105 }
158106
159- /**
160- * Slugify the value
161- *
162- * @param $value
163- */
164- public function setSlugAttribute ($ value )
107+ protected static function newFactory (): PostTypeFactory
165108 {
166- $ this -> attributes [ ' slug ' ] = Str:: slug ( $ value );
109+ return PostTypeFactory:: new ( );
167110 }
168111}
169112
0 commit comments