我是编程和laravel的新手,我想问如何通过使用Isilowongan表中的mahasiswa_id属性检测到Isilowongan表中未填充的Reqlowongan表中的数据,当前的mahasiswa_id正在登录。所以当用户登录时,他们只看到Reqlowongan,他们没有在Isilowongan注册(Reqlowongan是我的表单,而Isilowongan是用户填写的表单的答案)怎么办?
这是我的表:https://i.stack.imgur.com/9vWcm.png
this is my controller:
public function index()
{
$role = auth()->user()->role;
$id = auth()->user()->id;
if($role =='mahasiswa'){
$lowongan = Reqlowongan::all();
return view('indexMhs', compact(['lowongan']));
}if($role =='instansi'){
$lowongan = auth()->user()->instansi->reqlowongan;
return view('indexIns', compact(['lowongan']));
}else{
$lowongan = Reqlowongan::all();
return view('IndexKp', compact(['lowongan']));
}
}
这是我的刀
@foreach($lowongan as $lowongan)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $lowongan->instansi->nama_instansi}}</th>
<td>{{ $lowongan->jenis_lowongan}}</th>
<td>{{ $lowongan->created_at->format('d/m/Y')}}</td>
<td class="text-center">
<a href="/instansi/{{$lowongan->id}}/list_mahasiswa" class="badge badge-warning ml-2">DAFTAR </a>
</td>
</tr>
@endforeach
我已经尝试使用where子句和if子句,但我不知道怎么做,我做不到,你能帮我吗?
after find role from user table在if语句中,必须像这样将表连接在一起
public function index()
{
$role = auth()->user()->role;
$id = auth()->user()->id;
if($role =='mahasiswa'){
$lowongan = user::join('mahasiswa','mahasiswa.user_id','user.id')
->join('isi_lowongan','isi_lowonan.mahasiswa_id','mahasiswa.id')
->join('req_lowongan','req_lowonan.id','isi_lowonan.reqlowongan_id')
->join('instansi','instansi.id','req_lowonan.instansi_id')
//->where('user.id','$id')
->select('req_lowonan.*','instansi.nama_instansi as nama_instansi');
return view('indexMhs', compact(['lowongan']));
}if($role =='instansi'){
$lowongan = user::join('instansi','instansi.user_id','user.id')
->join('req_lowongan','req_lowonan.instansi_id','instansi.id')
->select('req_lowonan.*','instansi.nama_instansi as nama_instansi');
return view('indexIns', compact(['lowongan']));
}else{
$lowongan = user::join('instansi','instansi.user_id','user.id')
->join('req_lowongan','req_lowonan.instansi_id','instansi.id')
->select('req_lowonan.*','instansi.nama_instansi as nama_instansi');
return view('IndexKp', compact(['lowongan']));
}
}
完成@foreach($lowongan as $item)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $item->nama_instansi}}</th>
<td>{{ $item->jenis_lowongan}}</th>
<td>{{ $item->created_at->format('d/m/Y')}}</td>
<td class="text-center">
<a href="/instansi/{{$item->id}}/list_mahasiswa" class="badge badge-warning ml-2">DAFTAR </a>
</td>
</tr>
@endforeach