2.1-2.4: install spatie/laravel-translatable, migrate to JSON, update models & controllers
Deploy Backend / deploy (push) Failing after 1m52s
Deploy Backend / deploy (push) Failing after 1m52s
This commit is contained in:
1 parent
75af8220a7
commit
37dd2c9d54
17 files changed
+453
-285
No files matched your search
@@ -11,13 +11,13 @@ class AboutMeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills.translations')->first();
|
||||
$aboutMe = AboutMe::with('skills')->first();
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills.translations')->findOrFail($id);
|
||||
$aboutMe = AboutMe::with('skills')->findOrFail($id);
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
@@ -42,24 +42,17 @@ class AboutMeController extends Controller
|
||||
|
||||
public function getTranslation($id, $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);
|
||||
$aboutMe = AboutMe::with('skills')->findOrFail($id);
|
||||
|
||||
if ($aboutMe->translations->isEmpty()) {
|
||||
if (!$aboutMe->hasTranslation('title', $locale)) {
|
||||
return response()->json(['message' => 'Translation not found', 'locale' => $locale], 404);
|
||||
}
|
||||
|
||||
$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,
|
||||
'title' => $skill->getTranslation('title', $locale),
|
||||
'description' => $skill->getTranslation('description', $locale),
|
||||
'image' => $skill->image,
|
||||
'link' => $skill->link,
|
||||
'percentage' => $skill->percentage,
|
||||
@@ -68,8 +61,8 @@ class AboutMeController extends Controller
|
||||
|
||||
$data = [
|
||||
'id' => $aboutMe->id,
|
||||
'title' => $translation->title,
|
||||
'description' => $translation->description,
|
||||
'title' => $aboutMe->getTranslation('title', $locale),
|
||||
'description' => $aboutMe->getTranslation('description', $locale),
|
||||
'image' => $aboutMe->image,
|
||||
'skills' => $skills,
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user