不能将stdClass类型的对象用作数组(视图:

时间:2019-04-20 16:48:00

标签: laravel-5 laravel-5.1

我想在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>

2 个答案:

答案 0 :(得分: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
     ]};
}

答案 1 :(得分:0)

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

 @foreach ($processmaster as $item)
   <tr>
    <td>{{ $item->pcm_id }}</td>
    <td>{{ $item->pcm_bname }}</td>
   </tr>
 @endforeac