我想使用laravel function isPermitted(req, res, next) {
var permitted = false;
// Your validation here, is your user permitted with this access or not.
if (permitted) {
next();
} else {
res.send('Sorry, you are not belong here.');
}
}
/* GET home page. */
router.get('/', isPermitted, function(req, res, next) {
//console.log("pending data");
res.locals.connection.query('SELECT id,name,email,username,address,phone,status FROM user', function (error, results, fields) {
if (error) throw error;
res.send(JSON.stringify(results));
});
});
在名为schedule
的varchar列中过滤年份。但是,它返回一个错误,如下图所示。还有一件事是,我没有将每个人都在使用的数据库中的whereYear()
指向whereYear
日期列。下面是我的代码。请帮忙。谢谢。
控制器:
created_at
数据库中的列$year = $request['bill_year'];
$month = $request['bill_month'];
$period = $request['bill_period'];
if( is_numeric($year) ){
$amortizations = Amortization::whereYear('schedule', $year)->where('bill_status',0)->get();
if($amortizations){
$notification = "Success";
} else{
$notification = "Failed";
}
return json_encode(array('notify'=>$notification, 'amortizations' => $amortizations, 'year' => $year, 'month' => $month, 'period' => $period));
}
错误:
答案 0 :(得分:0)
使用Y-m-d H:i:s时间戳格式的年份
use DB;
$amortizations = Amortization::where( DB::raw('YEAR(schedule)'), $year )->where('bill_status',0)->get();
或
$amortizations = Amortization::whereRaw('YEAR(schedule) = '.$year)->where('bill_status',0)->get();