[英]Laravel 5.6 - Get First Key from DB JSON Value
In DB I have saved value like this: 在数据库中,我这样保存了价值:
["IMG_4772.JPG","IMG_4775.JPG"]
In my view I'm trying to get first key like this: 在我看来,我试图像这样获得第一把钥匙:
background-image: url( {{ asset('img/ads/' . json_decode($ad->images, true)[0]) }} );
While inspecting element URL looks perfectly, as needed - /public/img/ads/IMG_4772.JPG
. 在检查元素URL时,根据需要看起来很完美-/
/public/img/ads/IMG_4772.JPG
。 I'm also able to copy/paste/open this URL in my browser and see the pic. 我还可以在浏览器中复制/粘贴/打开此URL并查看图片。
But the console gives me an error GET /public/img/ads/IMG_4772.JPG 0 ()
and the pic is not displayed as background-image of the block. 但是控制台给我一个错误
GET /public/img/ads/IMG_4772.JPG 0 ()
并且该图片未显示为该块的背景图像。 What is the problem? 问题是什么?
Controller: 控制器:
if ( $request->hasfile('images') ) {
foreach ( $request->file('images' ) as $image) {
$name = $image->getClientOriginalName();
$image->move(public_path() . '/img/ads/', $name);
$data[] = $name;
}
}
$ad->images = json_encode($data);
尝试添加斜杠
background-image: url('{{ asset('img/ads/' . json_decode($ad->images, true)[0]) }}');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.