连接表错误未定义属性

时间:2017-03-09 05:57:57

标签: php html mysql laravel laravel-5

你好我想问你们关于我的问题,请帮助我......

首先,我有两张桌子'Keluhans'和'Tindakans'然后我想要显示来自tb keluhans +'perbaikan_sementara的'produk,username,masalah'和来自tb tindakans的target_verifikasi'

这是我的代码,idk为什么结果是Undefined属性:stdClass :: $ id in View

我的控制器功能

public function lihattindaklanjut(){
    $halaman = "tindaklayanan";
    $keluhan_list=DB::table('keluhans')
    ->select(DB::raw('id,produk,username,masalah'))
    ->where('status','=','Proses')->get();

    $rows = DB::table('tindakans')
    ->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
    ->select(DB::raw('produk', 'username', 'masalah','perbaikan_sementara', 'target_verifikasi', 'keluhans.id'))->get();

    return view('layanankonsumen.lihattindaklanjut',compact('halaman','keluhan_list','rows'));
}

我的观点

<h4>Daftar Tindakan yang Dilakukan</h4><hr>
    <br><br>  
    <hr>
    @if (!empty($rows))
      <table class="striped bordered">
        <thead>
            <tr>
              <th hidden="true">id</th>
              <th>Produk</th>                                 
              <th>Pelanggan</th>
              <th>Masalah</th>
              <th>Perbaikan Sementara</th>
              <th>Target Verifikasi</th>                                       
            @if (Auth::check() && (Auth::user()->level == 'MR' || Auth::user()->level == 'PDD'))
              <th colspan="4" style="text-align:center;">Action</th>
            @endif
          </tr>
        </thead>
        <tbody>                        
          <?php foreach($rows as $value): ?>
            <tr>
              <td hidden="true">{{$value->id}}</td>
              <td>{{$value->produk}}</td>                                 
              <td>{{$value->username}}</td>
              <td>{{$value->masalah}}</td>
              <td>{{$value->perbaikan_sementara}}</td>
              <td>{{$value->target_verifikasi}}</td>
              <td>
              @if (Auth::check() && (Auth::user()->level == 'MR' || Auth::user()->level == 'PDD'))
                <td><a href="{{URL::to('tindaklanjut/'. $value->id)}}" class="btn">Detail</a>
                <td><a href="{{URL::to('tindaklanjut/'. $value->id)}}" class="btn">Edit</a>
                <td><a href="{{URL::to('tindaklanjut/'. $value->id)}}" class="btn">Delete</a>
              @endif
              </td>                                
              </td>
            </tr>
          <?php endforeach?>
        </tbody>
    </table>
  @else
    <h5>Tidak ada data Tindakan</h5>
  @endif
</div>

1 个答案:

答案 0 :(得分:0)

现在它的工作谢谢

$rows = DB::table('tindakans')
    ->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
    ->select(DB::raw('id_keluhan, produk, username, masalah, perbaikan_sementara, target_verifikasi, keluhans.id'))->get();

我错了选择所以我很抱歉。谢谢