1、控制器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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 ; |
1
|
->with( 'datas' , $datas [0]) //遍历到视图 |
2、view
1
|
<span>{{ $datas [ 'name' ]}}</span> |
1
2
3
4
5
|
@ if ( $datas [ 'status' ]==1) <span style= "color:red;" >上架中</span> @ else <span style= "color: green;" >已上架</span> @ endif |
3、js 注意:jquery,jquery-form.js layer插件的引入 bootstrap相关的引入
1
2
|
$( "#addForm" ).ajaxSubmit({ url: "{{url('/admin/commodity/update/'.$datas['id'])}}" , |
以上这篇laravel 关联关系遍历数组的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/gaokcl/article/details/76973159