我将“hello,world”作为数组存储在 mysql 数据库中,然后尝试使用以下查询进行检索
@php
$post_id = $post->id;
$result= DB::table('posts')
->select('tags')
->where('id', '=', $post_id)
->get();
echo($result);
@endphp
回显结果为:
[{"tags":"hello,world"}]
我需要为上面的结果回显单个值
hello
world
最佳答案
@php
$post_id = $post->id;
$result= DB::table('posts')
->select('tags')
->where('id', '=', $post_id)
->first();
$tags = $results->tags;
$tagsArray = explode(',', $tags);
@endphp
现在
@foreach($tagsArray as $ta)
{{ $ta }} <br />
@endforeach
你的输出将是
hello
world
关于mysql - Laravel DB 查询数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49318034/