I am trying to pass a variable in my query. But error occurs: "undefined variable $month
"
here is my controller part
public function due(Request $request){
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
$month = $request->month;
if(isset($month)) {
try {
$val=DB::connection()->getDatabaseName();
if(DB::connection()->getDatabaseName()) {
$month=$month;
$bRecord=DB::table('clients')->whereNotIn('ClientID', function($q){
$q->select('ClientID')->from('bills')
->where(function ($query) use($month) { //it shows $month is undefined, but why ??
$query->whereMonth('Date', '=', $month);
});
})->paginate(10);
return view('bills.dueRecord')->with('bRecord', $bRecord);
}else{
$er="/connection status: database error";
return view('home')->with('error',$er); //'error' is passed to home
}
} catch (\Exception $e){
$er="/connection status: database error";
return view('errors/503')->with('error',$er);
}
}
}else{
}
got my answer. I just need to pass the scope of $month two times in the query.
$bRecord=DB::table('clients')->whereNotIn('ClientID', function($q) use($month){
$q->select('ClientID')->from('bills')
->where(function ($query) use($month) {
$query->whereMonth('Date', '=', $month);
});
})->paginate(10);