发布于 2018-08-23 08:56:37
简短的答案是@Sang发布的一句话:与implode()相反的是explode()。
不过,我要添加一种更像“Laravel式”的方法:
假设您有一个Article模型,那么添加一个访问器:
class Article extends Model {
...
public function getImagesListAttribute() {
return collect(explode('|', $this->images));
}
...
}然后:
$article = Article::find(1);
var_dump($article->images_list); //would be a Collection of strings (which are your image names)更多关于访问器的信息:https://laravel.com/docs/5.6/eloquent-mutators#defining-an-accessor
更多关于集合的信息:https://laravel.com/docs/5.6/collections
发布于 2018-08-23 08:51:18
您只需要从数据库中explode数据,然后显示它。
$images = explode('|', $post->image);
@foreach ($images as $image)
<img src="{{ url($image) }} alt="image" />
@endforeach然后可以使用OwlCarousel https://owlcarousel2.github.io/OwlCarousel2/创建幻灯片。
可以使用此示例https://owlcarousel2.github.io/OwlCarousel2/demos/basic.html创建基本滑块。
例:在你的刀片视图中
<div class="owl-carousel owl-theme">
@foreach (explode('|', $post->image) as $image)
<div class="item"><img src="{{ url($image) }} alt="image" /></div>
@endforeach
</div>https://stackoverflow.com/questions/51981587
复制相似问题