Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-在blade.php中显示数组中的第一个图像_Php_Laravel - Fatal编程技术网

Laravel-在blade.php中显示数组中的第一个图像

Laravel-在blade.php中显示数组中的第一个图像,php,laravel,Php,Laravel,我试图显示这个数组的第一个图像[“11.jpg”,“16.jpg”],该数组存储在名为images的表列中。我在写作 <img src="{{ asset('images/properties/'. $files->images) }}" class=""> images)}“class=”“> 在my blade.php中 当我检查元素时,没有显示任何内容,但它与此一起出现 <img src="http://127.0.0.1:8000/images/propert

我试图显示这个数组的第一个图像[“11.jpg”,“16.jpg”],该数组存储在名为images的表列中。我在写作

<img src="{{ asset('images/properties/'. $files->images) }}" class="">
images)}“class=”“>
在my blade.php中
当我检查元素时,没有显示任何内容,但它与此一起出现

<img src="http://127.0.0.1:8000/images/properties/["11.jpg","16.jpg"]" class="">

我还尝试用此代码显示数组中的第一项,但图像没有显示。 如何在blade.php中显示第一个图像

<img src="{{ asset('images/properties/'. $files->images[0]) }}" class="">
images[0])}“class=”“>
首先使用数组()

array_first函数返回数组的第一个元素

必须使用
json\u encode
存储数组。在检索时,只需使用
json\u decode
对数据进行解码

<img src="{{ asset('images/properties/'. array_first(json_decode($files->images))) }}" />
images)))}}/>

哇!!!我找到了解决办法。 答案是使用json_decode()函数

<?php  $property_images = json_decode($files->images);?>
<img src="{{ asset('images/properties/'. $property_images[0]) }}" class="">


您可以使用它,它不显示,这是我检查元素时的结果,我希望元素如下所示。数组变量是什么?您的代码不工作,它显示了为foreach()first check
array\u first($files->images)提供的错误异常(E\u ERROR)无效参数
在控制器中,它是否工作?刀片服务器中是否有任何循环?是的,有一个循环,您确定所有属性都有多个映像吗?