Skip to content

Commit e6db974

Browse files
committed
feat: add SEO bridge controller and view to dynamically render meta tags for various routes
1 parent 96bfeb4 commit e6db974

File tree

4 files changed

+104
-3
lines changed

4 files changed

+104
-3
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\Models\Product;
7+
use App\Models\Shop;
8+
use Illuminate\Support\Facades\Log;
9+
use Illuminate\Support\Facades\URL;
10+
use Illuminate\Support\Str;
11+
12+
class SeoBridgeController extends Controller
13+
{
14+
public function __invoke(Request $request)
15+
{
16+
// L'URL envoyée par le .htaccess (ex: https://akevas.com/product/iphone-15)
17+
$fullUrl = $request->query('url');
18+
if (!$fullUrl) return abort(404);
19+
20+
$api_url = "https://api-akevas.akevas.com";
21+
22+
$host = parse_url($fullUrl, PHP_URL_HOST) ?? '';
23+
$path = parse_url($fullUrl, PHP_URL_PATH) ?? '/';
24+
25+
Log::info($host);
26+
Log::info($path);
27+
// Valeurs par défaut (Si aucune règle ne correspond)
28+
$data = [
29+
'title' => "Akevas - Shopping & Business",
30+
'description' => "La plateforme de commerce de référence.",
31+
'image' => asset('home.png'),
32+
'url' => $fullUrl
33+
];
34+
35+
// --- 1. DOMAINE CLIENT (akevas.com) ---
36+
if ($host === 'akevas.com') {
37+
38+
// Page Produit : akevas.com/product/slug
39+
if (Str::contains($path, '/produit/')) {
40+
$slug = Str::after($path, '/produit/');
41+
$product = Product::where('product_url', $slug)->first();
42+
if ($product) {
43+
$data['title'] = $product->product_name . " | Akevas";
44+
$data['description'] = Str::limit($product->product_description, 160);
45+
$data['image'] = URL("/storage/" . $product->product_profile);
46+
}
47+
}
48+
49+
// Page Boutique vue par le client : akevas.com/shop/slug
50+
elseif (Str::contains($path, '/shop/')) {
51+
$slug = Str::after($path, '/shop/');
52+
$shop = Shop::where('id', $slug)->first();
53+
if ($shop) {
54+
$data['title'] = "Boutique " . $shop->shop_name . " | Akevas";
55+
$data['description'] = $shop->shop_description;
56+
$data['image'] = $shop->shop_profile;
57+
}
58+
}
59+
}
60+
61+
// --- 2. DOMAINE VENDEUR (seller.akevas.com) ---
62+
elseif ($host === 'seller.akevas.com') {
63+
$data['title'] = "Espace Vendeur - Akevas";
64+
$data['description'] = "Gérez votre boutique et vos ventes sur Akevas.";
65+
$data['image'] = asset('images/meta-seller.png');
66+
}
67+
68+
// --- 3. DOMAINE LIVREUR (delivery.akevas.com) ---
69+
elseif ($host === 'delivery.akevas.com') {
70+
$data['title'] = "Espace Livreur - Akevas";
71+
$data['description'] = "Gérez vos livraisons et vos revenus.";
72+
$data['image'] = asset('images/meta-delivery.png');
73+
}
74+
75+
return view('seo_bridge', compact('data'));
76+
}
77+
}

public/home.png

547 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="fr">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>{{ $data['title'] }}</title>
7+
<meta name="description" content="{{ $data['description'] }}">
8+
9+
<meta property="og:title" content="{{ $data['title'] }}">
10+
<meta property="og:description" content="{{ $data['description'] }}">
11+
<meta property="og:image" content="{{ $data['image'] }}">
12+
<meta property="og:url" content="{{ $data['url'] }}">
13+
<meta property="og:type" content="product">
14+
15+
<meta name="twitter:card" content="summary_large_image">
16+
<meta name="twitter:image" content="{{ $data['image'] }}">
17+
</head>
18+
19+
<body>
20+
<h1>{{ $data['title'] }}</h1>
21+
<p>{{ $data['description'] }}</p>
22+
<img src="{{ $data['image'] }}" />
23+
</body>
24+
25+
</html>

routes/web.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Controllers\SeoBridgeController;
34
use Illuminate\Support\Facades\Route;
45

56
/*
@@ -13,6 +14,4 @@
1314
|
1415
*/
1516

16-
Route::get('/', function () {
17-
return view('welcome');
18-
});
17+
Route::get('render-seo', SeoBridgeController::class);

0 commit comments

Comments
 (0)