feat: add career application support for blog authors and expand blog status workflows
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Filament\Admin\Resources\Components\TranslationTabs;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -80,11 +81,17 @@ class BlogForm
|
||||
->helperText(__('blog.featured_image_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
Placeholder::make('intern_author_info')
|
||||
->label('Stajyer Yazarı')
|
||||
->content(fn ($record) => $record?->careerApplication?->name ?? '-')
|
||||
->visible(fn ($record) => $record?->career_application_id !== null)
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('author_id')
|
||||
->label(__('blog.author_field'))
|
||||
->relationship('author', 'name')
|
||||
->default(auth()->id())
|
||||
->required()
|
||||
->nullable()
|
||||
->placeholder('Boş bırakılırsa stajyer yazarı veya Trunçgil')
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('category_id')
|
||||
@@ -110,7 +117,9 @@ class BlogForm
|
||||
->label(__('blog.status_field'))
|
||||
->options([
|
||||
'draft' => __('blog.status_draft'),
|
||||
'pending' => __('blog.status_pending'),
|
||||
'published' => __('blog.status_published'),
|
||||
'rejected' => __('blog.status_rejected'),
|
||||
'archived' => __('blog.status_archived'),
|
||||
])
|
||||
->default('draft')
|
||||
|
||||
@@ -76,7 +76,13 @@ class BlogsTable
|
||||
|
||||
TextColumn::make('author.name')
|
||||
->label(__('blog.table_author'))
|
||||
->searchable()
|
||||
->formatStateUsing(fn ($state, $record) => $record->author_name)
|
||||
->searchable(query: function ($query, string $search) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereHas('author', fn ($sub) => $sub->where('name', 'like', "%{$search}%"))
|
||||
->orWhereHas('careerApplication', fn ($sub) => $sub->where('name', 'like', "%{$search}%"));
|
||||
});
|
||||
})
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('category.name')
|
||||
|
||||
@@ -20,7 +20,7 @@ class BlogController extends Controller
|
||||
$settings = class_exists(Setting::class) ? (Setting::query()->first()) : null;
|
||||
|
||||
$query = class_exists(Blog::class)
|
||||
? Blog::with(['category', 'author'])
|
||||
? Blog::with(['category', 'author', 'careerApplication'])
|
||||
->withCount('comments')
|
||||
->published()
|
||||
: null;
|
||||
@@ -29,6 +29,9 @@ class BlogController extends Controller
|
||||
if ($query && $request->has('author') && $request->author) {
|
||||
$query = $query->where('author_id', $request->author);
|
||||
}
|
||||
if ($query && $request->has('intern') && $request->intern) {
|
||||
$query = $query->where('career_application_id', $request->intern);
|
||||
}
|
||||
|
||||
// Category filtresi
|
||||
if ($query && $request->has('category') && $request->category) {
|
||||
@@ -130,14 +133,14 @@ class BlogController extends Controller
|
||||
if (!$request->ajax()) {
|
||||
if (class_exists(Blog::class)) {
|
||||
// Karusel: Öne çıkarılan ya da en güncel 5 yazı
|
||||
$carouselPosts = Blog::with(['category', 'author'])
|
||||
$carouselPosts = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->published()
|
||||
->featured()
|
||||
->latest('published_at')
|
||||
->take(5)
|
||||
->get();
|
||||
if ($carouselPosts->isEmpty()) {
|
||||
$carouselPosts = Blog::with(['category', 'author'])
|
||||
$carouselPosts = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->published()
|
||||
->latest('published_at')
|
||||
->take(5)
|
||||
@@ -145,7 +148,7 @@ class BlogController extends Controller
|
||||
}
|
||||
|
||||
// Popüler Yazılar: En çok okunan 3 yazı
|
||||
$popularPosts = Blog::with(['category', 'author'])
|
||||
$popularPosts = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->published()
|
||||
->orderBy('view_count', 'desc')
|
||||
->take(3)
|
||||
@@ -224,14 +227,14 @@ class BlogController extends Controller
|
||||
if (!class_exists(Blog::class)) {
|
||||
abort(404);
|
||||
}
|
||||
$post = Blog::with(['category', 'author'])
|
||||
$post = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->withCount('comments')
|
||||
->published()
|
||||
->where('slug', $slug)
|
||||
->firstOrFail();
|
||||
|
||||
// İlgili blog gönderilerini al (aynı kategoriden, mevcut gönderi hariç)
|
||||
$relatedPosts = Blog::with(['category', 'author'])
|
||||
$relatedPosts = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->withCount('comments')
|
||||
->published()
|
||||
->where('id', '!=', $post->id)
|
||||
@@ -244,7 +247,7 @@ class BlogController extends Controller
|
||||
|
||||
// Eğer aynı kategoriden yeterli gönderi yoksa, diğer kategorilerden ekle
|
||||
if ($relatedPosts->count() < 4) {
|
||||
$additionalPosts = Blog::with(['category', 'author'])
|
||||
$additionalPosts = Blog::with(['category', 'author', 'careerApplication'])
|
||||
->withCount('comments')
|
||||
->published()
|
||||
->where('id', '!=', $post->id)
|
||||
|
||||
@@ -82,6 +82,36 @@ class Blog extends Model
|
||||
return '/blog/' . $this->slug;
|
||||
}
|
||||
|
||||
public function getAuthorNameAttribute()
|
||||
{
|
||||
if ($this->author) {
|
||||
return $this->author->name;
|
||||
}
|
||||
if ($this->careerApplication) {
|
||||
return $this->careerApplication->name;
|
||||
}
|
||||
return __('blog.default_author');
|
||||
}
|
||||
|
||||
public function getAuthorRoleAttribute()
|
||||
{
|
||||
if ($this->author && $this->author->role) {
|
||||
return $this->author->role;
|
||||
}
|
||||
if ($this->careerApplication) {
|
||||
return 'Stajyer Yazılım Geliştirici';
|
||||
}
|
||||
return 'Trunçgil Teknoloji Editörü';
|
||||
}
|
||||
|
||||
public function getAuthorAvatarUrlAttribute()
|
||||
{
|
||||
if ($this->author && $this->author->avatar) {
|
||||
return asset('storage/' . $this->author->avatar);
|
||||
}
|
||||
return asset('assets/img/avatars/u5.webp');
|
||||
}
|
||||
|
||||
public function getFeaturedImageUrlAttribute()
|
||||
{
|
||||
if ($this->featured_image) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class BlogStructuredData extends StructuredData
|
||||
'inLanguage' => app()->getLocale(),
|
||||
'author' => [
|
||||
'@type' => 'Person',
|
||||
'name' => $post->author->name ?? __('blog.default_author'),
|
||||
'name' => $post->author_name,
|
||||
],
|
||||
'publisher' => self::publisherNode(),
|
||||
'datePublished' => $publishedAt->toIso8601String(),
|
||||
|
||||
Reference in New Issue
Block a user