2.1-2.4: install spatie/laravel-translatable, migrate to JSON, update models & controllers
This commit is contained in:
1 parent
1dc72d8563
commit
db7ce880a0
17 files changed
+453
-285
No files matched your search
@@ -9,19 +9,17 @@ class ServiceController extends Controller
|
||||
{
|
||||
public function index($locale)
|
||||
{
|
||||
$services = Service::with(['translations' => function ($query) use ($locale) {
|
||||
$query->where('locale', $locale);
|
||||
}])->get();
|
||||
$services = Service::all();
|
||||
|
||||
$response = $services->map(function ($service) use ($locale) {
|
||||
return [
|
||||
'id' => $service->id,
|
||||
'imageSrc' => $service->imageSrc,
|
||||
'altText' => $service->translations->first()->altText ?? '',
|
||||
'altText' => '',
|
||||
'created_at' => $service->created_at,
|
||||
'updated_at' => $service->updated_at,
|
||||
'title' => optional($service->translations->first())->title,
|
||||
'description' => optional($service->translations->first())->description,
|
||||
'title' => $service->getTranslation('title', $locale),
|
||||
'description' => $service->getTranslation('description', $locale),
|
||||
];
|
||||
});
|
||||
|
||||
@@ -30,13 +28,13 @@ class ServiceController extends Controller
|
||||
|
||||
public function showTranslation($id, $locale)
|
||||
{
|
||||
$service = Service::with('translations')->findOrFail($id);
|
||||
$service = Service::findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'id' => $service->id,
|
||||
'imageSrc' => $service->imageSrc,
|
||||
'title' => $service->getTitle($locale),
|
||||
'description' => $service->getDescription($locale),
|
||||
'title' => $service->getTranslation('title', $locale),
|
||||
'description' => $service->getTranslation('description', $locale),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user