|
| 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 | +} |
0 commit comments