관리-도구
편집 파일: VideoController.php
<?php namespace App\Http\Controllers\Frontend; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Http; use App\Models\Product; class VideoController extends Controller { public function index() { $videoId = null; $title = null; $apiKey = env('YOUTUBE_API_KEY'); $handle = "Srilakshminarayanasilk"; try { // Get Channel ID from handle $channelResponse = Http::get('https://www.googleapis.com/youtube/v3/channels', [ 'part' => 'id', 'forHandle' => '@' . $handle, 'key' => $apiKey ]); $channelData = $channelResponse->json(); if (!empty($channelData['items'][0]['id'])) { $channelId = $channelData['items'][0]['id']; // Check Live Video $liveResponse = Http::get('https://www.googleapis.com/youtube/v3/search', [ 'part' => 'snippet', 'channelId' => $channelId, 'eventType' => 'live', 'type' => 'video', 'key' => $apiKey ]); $liveData = $liveResponse->json(); if (!empty($liveData['items'][0])) { $videoId = $liveData['items'][0]['id']['videoId'] ?? null; $title = $liveData['items'][0]['snippet']['title'] ?? null; } else { // If no live → Get Latest Video $latestResponse = Http::get('https://www.googleapis.com/youtube/v3/search', [ 'part' => 'snippet', 'channelId' => $channelId, 'order' => 'date', 'maxResults' => 1, 'type' => 'video', 'key' => $apiKey ]); $latestData = $latestResponse->json(); if (!empty($latestData['items'][0])) { $videoId = $latestData['items'][0]['id']['videoId'] ?? null; $title = $latestData['items'][0]['snippet']['title'] ?? null; } } } } catch (\Exception $e) { // Log error (optional but recommended) \Log::error('YouTube API Error: ' . $e->getMessage()); $videoId = null; $title = null; } $footerData = $this->getFooterData(); $videoProducts = Product::where('is_video_enabled', 1) ->where('status', 1) ->latest() ->take(8) ->get(); return view('admin-views.videos.index', compact('videoId', 'title', 'footerData','videoProducts')); } private function getFooterData(): array { return [ 'footer_logo' => getWebConfig(name: 'company_footer_logo'), 'company_name' => getWebConfig(name: 'company_name'), 'company_email' => getWebConfig(name: 'company_email'), 'company_phone' => getWebConfig(name: 'company_phone'), 'shop_address' => getWebConfig(name: 'shop_address'), 'business_pages'=> getWebConfig(name: 'business_pages'), 'social_media' => getWebConfig(name: 'social_media'), 'ios' => getWebConfig(name: 'ios'), 'android' => getWebConfig(name: 'android'), 'cookie_setting'=> getWebConfig(name: 'cookie_setting'), 'blog_feature_active_status' => getWebConfig(name: 'blog_feature_active_status'), 'flash_deals' => getWebConfig(name: 'flash_deals'), 'flash_deals_products' => getWebConfig(name: 'flash_deals_products'), 'copyright_text'=> getWebConfig(name: 'company_copyright_text'), ]; } }