亲宝软件园·资讯

展开

laravel 关联关系遍历数组的例子

人气:0

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

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论