doulanli6146 2019-01-04 07:11
浏览 38
已采纳

如何从数据库中检索json数据到laravel刀片

I'm using Laravel to build my system and I needed to send multiple option from drop down input field and it was done successfully by sending as json_encode.

but when I retrieve data to laravel blade, it display like this: ["Sinhala","Englis"]

How can I show it without brackets and commas? I tried json_decode and an error occurred (see image)

my database is like this Database

My Controller function

public function index(){
    $courses = Course::get();
    return view('Courses.courses')->with('courses', $courses);
}
  • 写回答

1条回答 默认 最新

  • duanlanqian9974 2019-01-04 07:35
    关注

    You can do like this using the json_decode function so you got the array of the values then make string using the implode function with comma separated.

    <?php
    
    $data = '["Sinhala", "English"]';
    
    $data = json_decode($data);
    
    echo implode(', ', $data);
    

    Output

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包
  • ¥15 comsol压电材料数据