ldc-bien-etre-animal/app/Http/Controllers/Front/HomeController.php

66 lines
2 KiB
PHP
Raw Normal View History

2026-08-28 08:40:04 +00:00
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Front;
use App\Services\NewsRepository;
use Inertia\Inertia;
use Inertia\Response;
use Uwil\LaravelCommon\Controllers\CommonController;
class HomeController extends CommonController
{
public function index(): Response
{
$trans = trans('home_page');
return Inertia::render('front/Pages/HomePage', [
2026-08-31 16:54:51 +02:00
'metaTitle' => $trans['meta']['title'],
'metaDescription' => $trans['meta']['description'],
'heroVideoSrc' => $trans['hero']['video_src'],
'stats' => $trans['chiffres_cles']['stats'],
'brands' => $trans['marques']['brands'],
'testimonials' => $this->getTestimonials($trans),
2026-08-28 08:40:04 +00:00
'featuredArticles' => $this->getFeaturedArticles(),
]);
}
2026-08-31 16:54:51 +02:00
/**
2026-08-28 08:40:04 +00:00
* @param array<string, mixed> $trans
* @return array<int, array<string, mixed>>
*/
private function getTestimonials(array $trans): array
{
/** @var array<int, array<string, mixed>> $testimonials */
$testimonials = $trans['rejoindre']['testimonials'] ?? [];
2026-08-31 16:54:51 +02:00
2026-08-28 08:40:04 +00:00
return collect($testimonials)
2026-08-31 16:54:51 +02:00
->map(fn ($t) => [
'quote' => $t['quote'],
'authorName' => $t['author_name'],
'authorRole' => $t['author_role'],
2026-08-28 08:40:04 +00:00
'authorPhoto' => $t['author_photo'],
2026-08-31 16:54:51 +02:00
'logo' => $t['logo'],
2026-08-28 08:40:04 +00:00
])->all();
}
2026-08-31 16:54:51 +02:00
/**
* @return array<int, array<string, mixed>>
*/
2026-08-28 08:40:04 +00:00
private function getFeaturedArticles(): array
{
return collect(NewsRepository::all())
2026-08-31 16:54:51 +02:00
->take(3)
->map(fn ($a) => [
'slug' => $a['slug'],
'title' => $a['title'],
'excerpt' => $a['excerpt'],
'date' => $a['date'],
'rotation' => $a['rotation'],
])
->values()
->all();
2026-08-28 08:40:04 +00:00
}
}