不能使用stdClass类型的对象作为数组(查看:

问题描述 投票:0回答:2

我想在1个视图中使用数据2查询但是

错误无法使用stdClass类型的对象作为数组

 (View:
     public function adtranspc(Request $request)
        {
          $writter = Writter::all();
             $processmaster = DB::table('rocessmaster')
             ->where('pcm_bname', 'LIKE', "%Social%")
             ->get();
          return view('processspj.adtranspc',[
                   'writter' => $writter,
                   'processmaster' => $processmaster
         ]};


      *This is my view (this error here)
       <table id="table2" class="table table-hover table-striped">
          <tr>
             <th scope="col"></th>
             <th scope="col">Colname1</th>
          </tr>
           @foreach ($processmaster as $item)
            <tr>
              <td>{{ $item['pcm_id'] }}</td>
              <td>{{ $item['pcm_bname'] }}</td>
            </tr>
           @endforeach
      </table>
laravel-5 laravel-5.1
2个回答
0
投票
This is my controller
public function adtranspc(Request $request)
    {
      $writter = Writter::all();
         $processmaster = DB::table('rocessmaster')
         ->where('pcm_bname', 'LIKE', "%Social%")
         ->get();

      return view('processspj.adtranspc',[
               'writter' => $writter,
               'processmaster' => $processmaster
     ]};
}

0
投票

您正在尝试将object值打印为array。您需要使用此更新代码,以这种方式访问​​您的对象值

 @foreach ($processmaster as $item)
   <tr>
    <td>{{ $item->pcm_id }}</td>
    <td>{{ $item->pcm_bname }}</td>
   </tr>
 @endforeac
© www.soinside.com 2019 - 2024. All rights reserved.