DDR爱好者之家 Design By 杰米

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 关联关系遍历数组的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米