這是我的SQL查詢PHP laravel未定義的變量:用戶ID在控制器
select * from users us join EmailBox em on us.userid = em.suserid
where em.status = "Delete" and (em.suserid="$userid" or em.riemailid="$user")
我要檢查任何一個領域,如果只有「suserid」或「riemailid」的結果。 所以我改變了這個laravel querybuilder。
$lists = EmailBox::join('users as us', 'EmailBox.suserid', '=', 'us.id')
->where('status' , 'Delete')
->where(function($query){
$query->where('suserid' , '$userid');
$query->orwhere('riemailid' , '$user');
})->paginate(5);
此查詢工作正常時,該值將被直接傳遞, 用戶ID直接傳遞1表示
$lists = EmailBox::join('users as us', 'EmailBox.suserid', '=', 'us.id')
->where('status' , 'Delete')
->where(function($query){
$query->where('suserid' , 1);
$query->orwhere('riemailid' , '$user');
})->paginate(5);
這是我在laravel代碼。 什麼是錯誤?
if(Auth::check()){
//if(Auth::user()->email!="")
$user=Auth::user()->email;
$userid=Auth::user()->id;
$lists = EmailBox::join('users as us', 'EmailBox.suserid', '=', 'us.id')
->where('status' , 'Delete')
->where(function($query){
$query->where('suserid' , '$userid');
$query->orwhere('riemailid' , '$user');
})->paginate(5);
$links = $lists->render();
return view('front.index', compact('lists', 'links'));
}
我得到錯誤$ userid變量是未定義的。
它會返回值1多數民衆贊成沒有問題 –