在Laravel中的刀片模板中的单个视图上与多个表分开显示多个变量数据

时间:2019-04-16 20:53:03

标签: laravel-5

我想在foreach循环中的同一视图上显示两个变量数据

var seen = {};
newArray = array.filter(function(obj) {
    if (seen[obj.field]) {
        if (seen[obj.field].includes(obj.environmentLabel) {
            return false;
        } else {
            seen[obj.field].push(obj.environmentLabel);
        }
    } else {
        seen[obj.field] = [obj.environmentLabel];
    }
    return true;
});

那么如何在laravel刀片模板上显示数据

    public function getWalletList()
    {
        $data = Data::orderBy('id','desc')->get()->toArray();
        $user_ids = array_column($data, 'id');
        $user_data = User::whereIn('id',$user_ids)->get()->toArray();
        $d= array('data'=>$data,'user'=>$user_data);
        return view('wallet_list', compact('d'));
    }

1 个答案:

答案 0 :(得分:0)

为什么不使用两个foreach?

   @foreach($d as $value)                                        
      <tr>
         <td>{{$value['wallet']['name']}}</td>
         <td>{{$value->user_id}}</td>
         <td>{{$value->price}}</td>
         <td>{{$value->price}}</td>
         <td>{{$value->updated_at}}</td>
      </tr>
   @endforeach
   @foreach($b as $value)                                        
      <tr>
         <td>{{$value['wallet']['name']}}</td>
         <td>{{$value->user_id}}</td>
         <td>{{$value->price}}</td>
         <td>{{$value->price}}</td>
         <td>{{$value->updated_at}}</td>
      <tr>
   @endforeach