Blogger Information
Blog 36
fans 2
comment 0
visits 23611
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
消灭left join 连表查询
Rambo-Yang
Original
907 people have browsed it

控制器代码

         $res = DB::table('shop')->get()->toArray(); //查出所有文章记录
         $cate = DB::table('shop_cate')->get()->toArray(); // 查出栏目所有记录
         $cates = [];
         foreach ($cate as $val)
         {
            $cates[$val->id] = $val->title; //以栏目id为下标 栏目名称为值 重新组一个新数组
         }

        foreach ($res as $key => $val){
            $res[$key] = (array)$val; //强制把对象转换为数组
        }
        return view('product.lists',['product'=>$res,'cate_title'=>$cates]); //传入视图

 视图代码

@foreach($product as $item)
    <tr>
        <td>{{$item['id']}}</td>
        <td>{{$cate_title[$item['cid']]}}</td>
        <td>{{$item['title']}}</td>
    </tr>
    @endforeach


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post