gpt4 book ai didi

php - Laravel/PHP-将YouTube视频嵌入到图像数组中

转载 作者:行者123 更新时间:2023-12-03 05:49:02 25 4
gpt4 key购买 nike

我对PHP和Laravel还是很陌生,并且我有这个登录页面,该页面在页面主体上显示图像。

我的客户想添加一个YouTube视频而不是其中一个图像,我不太确定该怎么做。

我尝试在foreach循环中使用$ counter添加一条if语句,当$ counter等于$ i时,它将显示嵌入式代码,但是我做错了或者只是不知道如何正确地做它出现在体内,而不是视频或图像。

会感谢所有的帮助,谢谢!

这是代码:

page.php:

public function index($path = "")
{

$data = $this->data;

$images = [
"images/portraits/1.jpg",
"images/portraits/2.jpg",
"images/portraits/3.jpg",
"images/portraits/4.jpg"
];

$data['images'] = $images;
$counter = 0;
$data['counter'] = $counter;
return view($this->folderPath."main",$data);
}

main.blade.php:
    @foreach($images as $i)
<?php if ($counter == 2)?>
<?php if ($counter == 2) ?>
<iframe
width="560" height="315"
src="https://www.youtube.com/embed/VIDEOID?
rel=0&amp;controls=0"
frameborder="0" allow="autoplay; encrypted-media"
allowfullscreen>
</iframe>
<div class="cbp-item">
<a href="{{$i}}" class="cbp-caption cbp-lightbox">
<div class="cbp-caption-defaultWrap">
<img src="{{str_replace(".jpeg","_mini.jpeg",str_replace(".jpg","_mini.jpg",$i))}}" alt="">
</div>
<div class="cbp-caption-activeWrap cbp-gray">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<i class="fa fa-expand enlarge-icon"></i>
</div>
</div>
</div>
</a>
</div>
@endforeach

最佳答案

您可以根据需要执行类似的操作
page.php:

public function index($path = "")
{

$data = $this->data;

$images = [
["type" => "image", "file" => "images/portraits/1.jpg"],
["type" => "image", "file" => "images/portraits/2.jpg"],
["type" => "image", "file" => "images/portraits/3.jpg"],
["type" => "video", "file" => "https://www.youtube.com/embed/tgbNymZ7vqY"]
];

$data['images'] = $images;
return view($this->folderPath."main",$data);
}
main.blade.php :

@foreach($images as $i)
<div class="cbp-item">
<a href="{{$i['file']}}" class="cbp-caption cbp-lightbox">
<div class="cbp-caption-defaultWrap">
@if($i['type'] == 'image')
<img src="{{str_replace(".jpeg","_mini.jpeg",str_replace(".jpg","_mini.jpg",$i['file']))}}" alt="">
@else
<iframe width="420" height="315"
src="{{ $i['file'] }}">
</iframe>
@endif
</div>
<div class="cbp-caption-activeWrap cbp-gray">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<i class="fa fa-expand enlarge-icon"></i>
</div>
</div>
</div>
</a>
</div>
@endforeach

关于php - Laravel/PHP-将YouTube视频嵌入到图像数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49771413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com