I'm quite new to Laravel, sorry if this is a simple question. In panitia controller if I use get()
I get: Trying to get property of non-object
If I use firstOrFail
I get: Call to undefined method Illuminate\Database\Query\Builder::firstOrFail()
If I use first()
, it works, but it will show only the first record
The problems is that this code is fine until I need join table.
PanitiaController
public function lihat($username)
{
$panitia=DB::table('panitia')
->join('detail', 'panitia.id_panitia', '=', 'detail.id_panitia')
->where('username', '=', $username)
->first();
return view('admin.lihat',compact('panitia'));
}
panitia view
@foreach ($panitias as $panitia)
<tr>
<td>{{ $panitia->id_panitia }}</td>
<td>{{ $panitia->username }}</td>
<td>{{ $panitia->nama }}</td>
<td><a href="{{url('/admin/panitia/lihat',$panitia->username)}}" class="btn btn-primary">Detail</a></td>
<td><a href="{{url('/admin/panitia/edit',$panitia->username)}}" class="btn btn-warning">Edit</a></td>
<td>
</td>
</tr>
@endforeach
lihat view
<div class="form-group">
<label for="isbn" class="col-sm-2 control-label">Id Panitia</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="id_panitia" placeholder={{ $panitia->id_panitia}} readonly>
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Nama</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" placeholder={{$panitia->username}} readonly>
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Nama</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nama" placeholder={{$panitia->nama}} readonly>
</div>
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire