@@ -7,28 +7,26 @@ trait HasTitleMenuLabelTrait
77 /**
88 * Get the display label for menu items.
99 * This implementation uses the 'title' field with locale support.
10+ * Assumes the model uses Spatie Laravel Translatable trait.
1011 */
1112 public function getMenuLabel (?string $ locale = null ): string
1213 {
1314 $ locale = $ locale ?: app ()->getLocale ();
1415
15- // Check if the model uses translations (like Spatie Laravel Translatable)
16- if (method_exists ($ this , 'getTranslation ' )) {
17- $ title = $ this ->getTranslation ('title ' , $ locale );
18- if (empty ($ title )) {
19- // Fallback to the configured fallback locale
20- $ title = $ this ->getTranslation ('title ' , config ('app.fallback_locale ' , 'en ' ));
21- }
22-
23- return $ title ?: 'Untitled ' ;
16+ // Get translated title (assumes HasTranslations trait is used)
17+ $ title = $ this ->getTranslation ('title ' , $ locale );
18+ if (empty ($ title )) {
19+ // Fallback to the configured fallback locale
20+ $ title = $ this ->getTranslation ('title ' , config ('app.fallback_locale ' , 'en ' ));
2421 }
2522
26- return $ this -> title ?: 'Untitled ' ;
23+ return $ title ?: 'Untitled ' ;
2724 }
2825
2926 /**
3027 * Scope to search for models that can be used in menu items.
3128 * This implementation searches in common searchable fields.
29+ * Assumes the model uses Spatie Laravel Translatable trait.
3230 */
3331 public function scopeSearchForMenuItems ($ query , string $ search )
3432 {
@@ -39,8 +37,7 @@ public function scopeSearchForMenuItems($query, string $search)
3937 $ searchableFields = ['name ' , 'intro ' , 'description ' , 'overview_title ' ];
4038 foreach ($ searchableFields as $ field ) {
4139 if (in_array ($ field , $ this ->getFillable ()) ||
42- (method_exists ($ this , 'getTranslatableAttributes ' ) &&
43- in_array ($ field , $ this ->getTranslatableAttributes ()))) {
40+ in_array ($ field , $ this ->getTranslatableAttributes ())) {
4441 $ query ->orWhere ($ field , 'like ' , "% {$ search }% " );
4542 }
4643 }
0 commit comments