feat: implement intern blog management system with approval workflows and administrative feedback

This commit is contained in:
Ümit Tunç
2026-07-29 16:18:21 +03:00
parent 7c04433f6d
commit aa003df568
8 changed files with 695 additions and 36 deletions
+99 -3
View File
@@ -3,8 +3,10 @@
namespace App\Http\Controllers;
use App\Models\CareerApplication;
use App\Models\Blog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class CareerController extends Controller
{
@@ -98,8 +100,11 @@ class CareerController extends Controller
'password' => 'required|string',
]);
$intern = CareerApplication::where('username', $request->username)
->where('type', 'internship')
$intern = CareerApplication::where('type', 'internship')
->where(function ($q) use ($request) {
$q->where('username', $request->username)
->orWhere('email', $request->username);
})
->first();
if (!$intern || !\Illuminate\Support\Facades\Hash::check($request->password, $intern->password)) {
@@ -124,18 +129,109 @@ class CareerController extends Controller
$intern = CareerApplication::findOrFail(session('intern_id'));
$days = self::getInternshipDates($intern->internship_start_date, $intern->internship_total_days);
$savedEntries = $intern->journalEntries()->get()->keyBy('day_number');
$blogs = $intern->blogs()->orderBy('created_at', 'desc')->get();
return view('front.career.intern_dashboard', [
'intern' => $intern,
'days' => $days,
'savedEntries' => $savedEntries,
'blogs' => $blogs,
'meta' => [
'title' => 'Stajyer Paneli',
'description' => 'Belgelerinizi buradan indirebilirsiniz.',
'description' => 'Staj belgelerinizi ve blog yazılarınızı yönetin.',
]
]);
}
public function saveInternBlog(Request $request)
{
if (!session()->has('intern_id')) {
return redirect()->route('intern.login')->with('error', 'Lütfen önce giriş yapın.');
}
$intern = CareerApplication::findOrFail(session('intern_id'));
$request->validate([
'blog_id' => 'nullable|integer|exists:blogs,id',
'title' => 'required|string|max:255',
'intern_category' => 'required|string|in:experience,technical_challenge,product_showcase',
'excerpt' => 'nullable|string|max:500',
'content' => 'required|string|min:50',
'featured_image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:5120',
'action_type' => 'required|string|in:draft,submit',
], [
'title.required' => 'Lütfen blog yazısı başlığını girin.',
'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.',
'featured_image.image' => 'Görsel geçerli bir resim dosyası olmalıdır.',
]);
$status = $request->action_type === 'draft' ? 'draft' : 'pending';
if ($request->filled('blog_id')) {
$blog = Blog::where('id', $request->blog_id)
->where('career_application_id', $intern->id)
->firstOrFail();
} else {
$blog = new Blog();
$blog->career_application_id = $intern->id;
}
// Handle slug
if (!$blog->exists || $blog->title !== $request->title) {
$baseSlug = Str::slug($request->title);
$slug = $baseSlug;
$count = 1;
while (Blog::where('slug', $slug)->where('id', '!=', $blog->id ?? 0)->exists()) {
$slug = $baseSlug . '-' . $count;
$count++;
}
$blog->slug = $slug;
}
$blog->title = $request->title;
$blog->intern_category = $request->intern_category;
$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);
if ($request->hasFile('featured_image')) {
if ($blog->featured_image && Storage::disk('public')->exists($blog->featured_image)) {
Storage::disk('public')->delete($blog->featured_image);
}
$blog->featured_image = $request->file('featured_image')->store('blogs', 'public');
}
$blog->save();
$msg = $status === 'draft' ? 'Blog yazısı taslak olarak kaydedildi.' : 'Blog yazısı incelemeye gönderildi.';
return redirect()->back()->with('success', $msg);
}
public function deleteInternBlog($id)
{
if (!session()->has('intern_id')) {
return redirect()->route('intern.login')->with('error', 'Lütfen giriş yapın.');
}
$blog = Blog::where('id', $id)
->where('career_application_id', session('intern_id'))
->firstOrFail();
if (in_array($blog->status, ['draft', 'pending', 'rejected'])) {
if ($blog->featured_image && Storage::disk('public')->exists($blog->featured_image)) {
Storage::disk('public')->delete($blog->featured_image);
}
$blog->forceDelete();
return redirect()->back()->with('success', 'Blog yazısı silindi.');
}
return redirect()->back()->with('error', 'Yayınlanmış blog yazıları silinemez.');
}
public function uploadInternshipForm(Request $request)
{
if (!session()->has('intern_id')) {