douhu2525 2018-10-04 05:33
浏览 325

在Laravel中查看如何json_decode URL

I json_encode URL data before send it to database. Now I am retriving those data in view page. But I need to json_decode it to get url link smootly. But in some part of code I couldn't do it.

My foreach for the url json_decode(link) not working and returns laravel error. The error is: Undefined variable: links (View: /var/www/html/laravel/resources/views/welcome.blade.php)

<tbody>
    @foreach($estates as $estate)
        <tr>
            <td>{{$estate->company_name}}</td>

            <?php
                $links = json_decode($estate->link); 
                $hrefs = "";
                foreach($links as $link){
                    $hrefs .= '<a href="'.$link.'" } target="_blank">{{$estate->name}}</a><br/>';
                }
                $hrefs .= "";
            ?>

            <td>{{$estate->address}}</td>
            <td>{{$estate->price}}</td>
            <td>{{$estate->hows_old}}</td>
            <td>{{$estate->extend}}</td>
            <td>{{$estate->rooms}}</td>
            <td>{{$estate->balcon_m2}}</td>
            <td>{{$estate->old}}</td>
            <td>{{$estate->entery}}</td>
        </tr>
    @endforeach
</tbody>

without json_decode estate->link is like this:

`http://localhost/[%22https:////www.31sumai.com//pid//about//%22,%22https:////www.31sumai.com//%22,%22https:////www.31sumai.com//mfr//K1503//%22,%22https:////www.31sumai.com//mfr//K1503//%22,%22http:////maps.google.com//maps?q=34.69465,135.519178%22,%22https:\/\/www.31sumai.com\/mfr\/K1503\/juko.htm]`

Here is the controller codes:

$estates = Estates::get(); 

$data['estates'] = $estates; 
return view('welcome', $data); 

Thanks for helping me out.

  • 写回答

1条回答 默认 最新

  • duanqiongdu9916 2018-10-04 05:57
    关注

    If you really want to use json encoded data in a view, use json_decode() in foreach:

    @foreach(json_decode($estate->link, true) as $value)
        $hrefs .= '<a href="'.$value.'" } target="_blank">{{$estate->name}}</a><br/>'; 
    @endforeach
    
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型