feat: implement real-time SEO character counters and improve default avatar handling and translation logic.
This commit is contained in:
@@ -146,12 +146,20 @@ class BlogForm
|
||||
TextInput::make('meta_title')
|
||||
->label(__('blog.meta_title_field'))
|
||||
->maxLength(60)
|
||||
->extraInputAttributes(['maxlength' => 60])
|
||||
->live(debounce: 200)
|
||||
->hint(fn ($state) => mb_strlen((string) $state) . ' / 60')
|
||||
->hintColor(fn ($state) => mb_strlen((string) $state) > 60 ? 'danger' : 'gray')
|
||||
->helperText(__('blog.meta_title_helper')),
|
||||
|
||||
Textarea::make('meta_description')
|
||||
->label(__('blog.meta_description_field'))
|
||||
->rows(3)
|
||||
->maxLength(160)
|
||||
->extraInputAttributes(['maxlength' => 160])
|
||||
->live(debounce: 200)
|
||||
->hint(fn ($state) => mb_strlen((string) $state) . ' / 160')
|
||||
->hintColor(fn ($state) => mb_strlen((string) $state) > 160 ? 'danger' : 'gray')
|
||||
->helperText(__('blog.meta_description_helper'))
|
||||
->columnSpanFull(),
|
||||
])
|
||||
|
||||
@@ -15,12 +15,20 @@ class SeoSection
|
||||
TextInput::make('meta_title')
|
||||
->label(__('pages.meta_title_field'))
|
||||
->maxLength(60)
|
||||
->extraInputAttributes(['maxlength' => 60])
|
||||
->live(debounce: 200)
|
||||
->hint(fn ($state) => mb_strlen((string) $state) . ' / 60')
|
||||
->hintColor(fn ($state) => mb_strlen((string) $state) > 60 ? 'danger' : 'gray')
|
||||
->helperText(__('pages.meta_title_helper_text')),
|
||||
|
||||
Textarea::make('meta_description')
|
||||
->label(__('pages.meta_description_field'))
|
||||
->rows(3)
|
||||
->maxLength(160)
|
||||
->extraInputAttributes(['maxlength' => 160])
|
||||
->live(debounce: 200)
|
||||
->hint(fn ($state) => mb_strlen((string) $state) . ' / 160')
|
||||
->hintColor(fn ($state) => mb_strlen((string) $state) > 160 ? 'danger' : 'gray')
|
||||
->helperText(__('pages.meta_description_helper_text'))
|
||||
->columnSpanFull(),
|
||||
])
|
||||
|
||||
@@ -156,6 +156,8 @@ class CareerController extends Controller
|
||||
'title' => 'required|string|max:255',
|
||||
'intern_category' => 'required|string|in:experience,technical_challenge,product_showcase',
|
||||
'excerpt' => 'nullable|string|max:500',
|
||||
'meta_title' => 'nullable|string|max:60',
|
||||
'meta_description' => 'nullable|string|max:160',
|
||||
'content' => 'required|string|min:50',
|
||||
'featured_image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:5120',
|
||||
'action_type' => 'required|string|in:draft,submit',
|
||||
@@ -164,6 +166,8 @@ class CareerController extends Controller
|
||||
'intern_category.required' => 'Lütfen bir kategori seçin.',
|
||||
'content.required' => 'Lütfen blog yazısı içeriğini girin.',
|
||||
'content.min' => 'Blog içeriği en az 50 karakter olmalıdır.',
|
||||
'meta_title.max' => 'Meta Başlık en fazla 60 karakter olmalıdır.',
|
||||
'meta_description.max' => 'Meta Açıklama en fazla 160 karakter olmalıdır.',
|
||||
'featured_image.image' => 'Görsel geçerli bir resim dosyası olmalıdır.',
|
||||
]);
|
||||
|
||||
@@ -195,8 +199,8 @@ class CareerController extends Controller
|
||||
$blog->excerpt = $request->excerpt;
|
||||
$blog->content = $request->content;
|
||||
$blog->status = $status;
|
||||
$blog->meta_title = $request->title;
|
||||
$blog->meta_description = Str::limit(strip_tags($request->excerpt ?: $request->content), 160);
|
||||
$blog->meta_title = $request->filled('meta_title') ? Str::limit($request->meta_title, 60, '') : Str::limit($request->title, 60, '');
|
||||
$blog->meta_description = $request->filled('meta_description') ? Str::limit($request->meta_description, 160, '') : Str::limit(strip_tags($request->excerpt ?: $request->content), 160, '');
|
||||
|
||||
if ($request->hasFile('featured_image')) {
|
||||
if ($blog->featured_image && Storage::disk('public')->exists($blog->featured_image)) {
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ class Blog extends Model
|
||||
if ($this->author && $this->author->avatar) {
|
||||
return asset('storage/' . $this->author->avatar);
|
||||
}
|
||||
return asset('assets/img/avatars/u5.webp');
|
||||
return asset('assets/img/avatars/avatar-default.svg');
|
||||
}
|
||||
|
||||
public function getFeaturedImageUrlAttribute()
|
||||
|
||||
@@ -45,14 +45,14 @@ trait HasTranslations
|
||||
// 1. Try translations table
|
||||
$translation = $this->getTranslation($fieldName, $languageCode);
|
||||
|
||||
if ($translation && !empty($translation->field_value)) {
|
||||
if ($translation && $this->hasValidTranslationContent($translation->field_value)) {
|
||||
return $translation->field_value;
|
||||
}
|
||||
|
||||
// 2. Fallback to default language from translations table
|
||||
if ($fallback && $languageCode !== $this->getDefaultLanguageCode()) {
|
||||
$defaultTranslation = $this->getTranslation($fieldName, $this->getDefaultLanguageCode());
|
||||
if ($defaultTranslation && !empty($defaultTranslation->field_value)) {
|
||||
if ($defaultTranslation && $this->hasValidTranslationContent($defaultTranslation->field_value)) {
|
||||
return $defaultTranslation->field_value;
|
||||
}
|
||||
}
|
||||
@@ -267,6 +267,23 @@ trait HasTranslations
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if translation content has meaningful text or media
|
||||
*/
|
||||
protected function hasValidTranslationContent(mixed $value): bool
|
||||
{
|
||||
if (empty($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$stripped = trim(strip_tags($value, '<img><iframe><video><audio>'));
|
||||
return $stripped !== '';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translatable fields for this model
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user