99use Illuminate \Database \Eloquent \Relations \BelongsTo ;
1010use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
1111use Illuminate \Database \Eloquent \SoftDeletes ;
12+ use Illuminate \Database \Eloquent \Casts \Attribute ;
1213use stdClass ;
1314use Symfony \Component \ClassLoader \ClassMapGenerator ;
1415
@@ -133,26 +134,33 @@ public function tags()
133134 $ id = $ this ->id ;
134135 $ tags = ItemTag::select ('tag_id ' )->where ('item_id ' , $ id )->pluck ('tag_id ' )->toArray ();
135136 $ tagdetails = self ::select ('id ' , 'title ' , 'url ' , 'pinned ' )->whereIn ('id ' , $ tags )->get ();
136- //print_r($tags);
137- if (in_array (0 , $ tags )) {
138- $ details = new self ([
139- 'id ' => 0 ,
140- 'title ' => __ ('app.dashboard ' ),
141- 'url ' => '' ,
142- 'pinned ' => 0 ,
143- ]);
144- $ tagdetails ->prepend ($ details );
145- }
146137
147138 return $ tagdetails ;
148139 }
149140
141+ protected function title (): Attribute
142+ {
143+ return Attribute::make (
144+ get: fn (mixed $ value ) => ($ value === 'app.dashboard ' ? __ ('app.dashboard ' ) : $ value ),
145+ );
146+ }
147+
148+ protected function tagUrl (): Attribute
149+ {
150+ return Attribute::make (
151+ get: fn (mixed $ value , array $ attributes ) => ($ attributes ['id ' ] === 0 ? '0-dash ' : $ attributes ['url ' ]),
152+ );
153+ }
154+
150155 public function getTagClass (): string
151156 {
152157 $ tags = $ this ->tags ();
153158 $ slugs = [];
154159
155160 foreach ($ tags as $ tag ) {
161+ if ($ tag ->id === 0 ) {
162+ $ tag ->url = '0-dash ' ;
163+ }
156164 if ($ tag ->url ) {
157165 $ slugs [] = 'tag- ' .$ tag ->url ;
158166 }
@@ -161,6 +169,20 @@ public function getTagClass(): string
161169 return implode (' ' , $ slugs );
162170 }
163171
172+ public function getTagList (): string
173+ {
174+ $ tags = $ this ->tags ();
175+ $ titles = [];
176+ // print_r($tags);
177+ foreach ($ tags as $ tag ) {
178+ if ($ tag ->title ) {
179+ $ titles [] = $ tag ->title ;
180+ }
181+ }
182+
183+ return implode (', ' , $ titles );
184+ }
185+
164186 public function parents (): BelongsToMany
165187 {
166188 return $ this ->belongsToMany (Item::class, 'item_tag ' , 'item_id ' , 'tag_id ' );
0 commit comments