Added YouTube video fetching functionality and update landing page to display videos

This commit is contained in:
2025-07-10 13:59:05 +05:45
parent d85b5a3662
commit 6c2da0d37c
4 changed files with 78 additions and 38 deletions

View File

@ -9,6 +9,7 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http;
function pre($object, $die = false)
{
@ -581,8 +582,18 @@ if (!function_exists('NepaliMonthNameByNumber')) {
function NepaliMonthNameByNumber($number)
{
$MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
"Baisakh",
"Jestha",
"Ashad",
"Shrawan",
"Bhadra",
"Asoj",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
);
return $MonthNames[$number - 1];
}
@ -593,8 +604,18 @@ if (!function_exists('NepaliMonthName')) {
{
$Month = NepaliMonth($engDate);
$MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
"Baisakh",
"Jestha",
"Ashad",
"Shrawan",
"Bhadra",
"Asoj",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
);
return $MonthNames[$Month - 1];
}
@ -627,7 +648,7 @@ function pushScriptToFooter($script)
}
function sectionHeader($text, $sectiontitle = null)
{
$texts=explode(" ",$text);
$texts = explode(" ", $text);
?>
<div class="row text-center intro">
@ -636,7 +657,8 @@ function sectionHeader($text, $sectiontitle = null)
<span class="pre-title"><?php echo $sectiontitle; ?></span>
<?php endif; ?>
<h2 class="ylw-clr"><?php echo $texts[0]; unset($texts[0]); ?> <span class="featured"><span><?php echo implode(" ",$texts); ?></span></span></h2>
<h2 class="ylw-clr"><?php echo $texts[0];
unset($texts[0]); ?> <span class="featured"><span><?php echo implode(" ", $texts); ?></span></span></h2>
</div>
@ -648,14 +670,35 @@ if (!function_exists('replace_img_src')) {
{
return preg_replace(
'/src="storage(\/[^"]*)"/',
'src="'.site_url().'storage$1"',
'src="' . site_url() . 'storage$1"',
$content
);
}
}
function fetchVideosByChannel($channelId)
{
$url = 'https://www.googleapis.com/youtube/v3/search';
$response = Http::get($url, [
'key' => 'AIzaSyAtDLH9Xzi_Mg-bvz4H27lvqQpT7AR2Bo0',
'channelId' => $channelId,
'part' => 'snippet',
'order' => 'date',
'maxResults' => '8',
'type' => 'video',
]);
if ($response->successful()) {
return $response->json()['items'];
}
return [];
}
function processForShortcode($content)
{
$content=replace_img_src($content);
$content = replace_img_src($content);
return preg_replace_callback('/\[([\w_]+)([^]]*)\]/', function ($matches) {
$shortcodeName = $matches[1];
$shortcodeAttributes = [];
@ -687,4 +730,4 @@ if (!function_exists('uploadImage')) {
$filePath = Storage::disk('public')->putFileAs($path, $file, $fileName);
return $filePath;
}
}
}

View File

@ -27,6 +27,7 @@ use Illuminate\Http\Request; // Import the Request class
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Http;
class WebsiteController extends Controller
{
@ -43,7 +44,11 @@ class WebsiteController extends Controller
public function home()
{
$channelId = env('CHANNEL_ID');
$videos = fetchVideosByChannel($channelId);
return view('landing.index', [
'videos' => $videos,
'banners' => Banners::get(),
'benefits' => Benefits::get(),
'success_stories' => Success_stories::get(),