简体   繁体   中英

How to retrieve json data from database to laravel blade

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 (见图片)

my database is like this 数据库

My Controller function

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

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM