internationalization added and backend updated until services
This commit is contained in:
1 parent
9bcf1fb0eb
commit
027d1090df
23 files changed
+935
-165
No files matched your search
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Website;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Website\AboutMe;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class AboutMeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills.translations')->first(); // بارگذاری مهارتها و ترجمهها
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills.translations')->findOrFail($id);
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$aboutMe = AboutMe::create($request->all());
|
||||
return response()->json($aboutMe, 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$aboutMe = AboutMe::findOrFail($id);
|
||||
$aboutMe->update($request->all());
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
AboutMe::destroy($id);
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
// متد جدید برای دریافت ترجمه بر اساس locale از کوکی
|
||||
public function getTranslation($id, $locale)
|
||||
{
|
||||
// بارگذاری AboutMe با ترجمههای مربوط به locale و مهارتها
|
||||
$aboutMe = AboutMe::with(['translations' => function ($query) use ($locale) {
|
||||
$query->where('locale', $locale);
|
||||
}, 'skills.translations' => function ($query) use ($locale) {
|
||||
$query->where('locale', $locale);
|
||||
}])->findOrFail($id);
|
||||
|
||||
// اگر ترجمه موجود نیست، میتوانید ترجمه پیشفرض یا خطا را برگردانید
|
||||
if ($aboutMe->translations->isEmpty()) {
|
||||
return response()->json(['message' => 'Translation not found', 'locale' => $locale], 404);
|
||||
}
|
||||
|
||||
// ترکیب اطلاعات AboutMe و ترجمه
|
||||
$translation = $aboutMe->translations->first(); // فقط یک ترجمه دریافت میکنیم
|
||||
$skills = $aboutMe->skills->map(function ($skill) use ($locale) {
|
||||
$translation = $skill->getTranslation($locale); // گرفتن ترجمه برای هر مهارت
|
||||
|
||||
return [
|
||||
'id' => $skill->id,
|
||||
'title' => $translation ? $translation->title : null, // عنوان از ترجمه
|
||||
'description' => $translation ? $translation->description : null, // توضیحات از ترجمه
|
||||
'image' => $skill->image, // تصویر
|
||||
'link' => $skill->link, // لینک
|
||||
'percentage' => $skill->percentage, // درصد
|
||||
];
|
||||
});
|
||||
|
||||
$data = [
|
||||
'id' => $aboutMe->id,
|
||||
'title' => $translation->title,
|
||||
'description' => $translation->description,
|
||||
'image' => $aboutMe->image,
|
||||
'skills' => $skills, // مهارتها اکنون بارگذاری شدهاند
|
||||
];
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user