1、控制器
public function show($id) { $goods = Goods::select('goods.*')->where('goods.id', '=', $id)->get(); $data = []; foreach($goods as $key=>$v) { $data[$key]['id'] = $v->id; $data[$key]['name'] = $v->name; $data[$key]['product_code'] = $v->product_code; $data[$key]['class_name'] = $v->goodsclass->class_name; $data[$key]['nums'] = $v->goodsNexus->count(); $data[$key]['price'] = $v->price; $data[$key]['goods_info'] = $v->goods_info; $data[$key]['img'] = $v->img; $data[$key]['site'] = $v->site; $data[$key]['work_company'] = $v->work_company; $data[$key]['status'] = $v->status; $data[$key]['area'] = $v->area; $data[$key]['product_at'] = $v->product_at; $data[$key]['created_at'] = $v->created_at; $data[$key]['productdate'] = $v->productdate; } $datas=$data;
->with( 'datas', $datas[0]) //遍历到视图
2、view
<span>{{$datas['name']}}</span>
@if($datas['status']==1) <span style="color:red;">上架中</span> @else <span style="color: green;">已上架</span> @endif
3、js 注意:jquery,jquery-form.js layer插件的引入 bootstrap相关的引入
$("#addForm").ajaxSubmit({ url:"{{url('/admin/commodity/update/'.$datas['id'])}}" ,
以上这篇laravel 关联关系遍历数组的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
laravel,关联,遍历,数组
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“laravel 关联关系遍历数组的例子”评论...