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

82 lines
2.8 KiB
PHP
Raw Permalink 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;
2026-09-03 16:52:27 +02:00
use Uwil\LaravelSchemaOrg\Services\SchemaOrgService;
2026-08-28 08:40:04 +00:00
class HomeController extends CommonController
{
2026-09-03 16:52:27 +02:00
public function index(SchemaOrgService $schemaOrg): Response
2026-08-28 08:40:04 +00:00
{
$trans = trans('home_page');
return Inertia::render('front/Pages/HomePage', [
'metaTitle' => $trans['meta']['seo_title'],
'metaDescription' => $trans['meta']['seo_description'],
'heroVideoSrc' => $trans['hero']['video_src'],
'heroMobileVideoSrc' => $trans['hero']['mobile_video_src'],
'stats' => $trans['chiffres_cles']['stats'],
'brands' => $trans['marques']['brands'],
'testimonials' => $this->getTestimonials($trans),
'featuredArticles' => $this->getFeaturedArticles(),
2026-09-03 16:52:27 +02:00
'schemas' => [
$schemaOrg->setWebPage()
2026-09-07 10:09:49 +02:00
->headline($trans['meta']['seo_title'])
->description($trans['meta']['seo_title'])
->name($trans['meta']['seo_title'])
2026-09-03 16:52:27 +02:00
->isAccessibleForFree(true)
->keywords(['page'])
2026-09-04 12:15:37 +02:00
->dateCreated(new \DateTimeImmutable('2026-09-03'))
->dateModified(new \DateTimeImmutable('2026-09-03'))
->datePublished(new \DateTimeImmutable('2026-09-03')),
2026-09-03 16:52:27 +02:00
],
2026-08-28 08:40:04 +00:00
]);
}
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-09-07 12:15:23 +02:00
->map(fn($t) => [
2026-08-31 16:54:51 +02:00
'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
{
2026-09-04 16:54:02 +02:00
$newsTrans = trans('news_page');
2026-09-07 10:09:49 +02:00
2026-08-28 08:40:04 +00:00
return collect(NewsRepository::all())
2026-08-31 16:54:51 +02:00
->take(3)
2026-09-07 12:15:23 +02:00
->map(fn($a) => [
2026-09-04 16:54:02 +02:00
'slug' => $a['slug'],
'title' => $a['title'],
'shortTitle' => $a['shortTitle'],
'date' => $a['date'],
'rotation' => $a['rotation'],
'category' => $newsTrans['themes'][$a['theme']],
2026-08-31 16:54:51 +02:00
])
->values()
->all();
2026-08-28 08:40:04 +00:00
}
}