任何人都可以帮我修复此代码吗?
public function caritindaklanjut(Request $request){
$halaman="tindaklayanan";
$cari = '%'.$request->search.'%';
$rows=DB::table('keluhans')
->select(DB::raw('id,produk,username,masalah,status,id_departemen'))
->where('status','=','Pending')
->where(function($query) {
$query->where('produk','like',$cari)
->orWhere('username','like',$cari)
->orWhere('masalah','like',$cari);
})->orderby('id','asc')->get();
它无法将$ cari传递给$ query并收到错误...请帮助:)
答案 0 :(得分:3)
添加use($cari)
:
->where(function($query) use($cari) {
答案 1 :(得分:2)
你需要有一个"使用($ cari)"声明在第二个匿名函数where():
public function caritindaklanjut(Request $request){
$halaman="tindaklayanan";
$cari = '%'.$request->search.'%';
$rows=DB::table('keluhans')
->select(DB::raw('id,produk,username,masalah,status,id_departemen'))
->where('status','=','Pending')
->where(function($query) use ($cari) {
$query->where('produk','like',$cari)
->orWhere('username','like',$cari)
->orWhere('masalah','like',$cari);
})->orderby('id','asc')->get();