[英]passing variable value into where condition laravel 5.2
Im trying to make where condition with variable value like this. 我试图使条件条件具有这样的可变值。
RekapController@show
RekapController @秀
public function show($tanggal)
{
$absen = Absen::where('DATE(created_at)', '=', $tanggal)
->get();
}
But when i run my code, it show an error 但是当我运行我的代码时,它显示一个错误
Column not found: 1054 Unknown column 'DATE(created_at)' in 'where clause' (SQL: select * from
absen
whereDATE(created_at)
= 2017-08-17)找不到列:
absen
子句'中的未知列'DATE(created_at)'(SQL:从*absen
中选择*DATE(created_at)
= 2017-08-17)
Thanks 谢谢
Since DATE(created_at)
inside where will search DATE(created_at)
for table columns but there is no such column and it doesn't know as a sql function so you can try in following way, 由于
DATE(created_at)
在其中搜索DATE(created_at)
的表列,但没有此类列,并且它也不是sql函数,因此您可以尝试以下方式,
$absen = Absen::select('absen.*',DB::raw('DATE(created_at) as date'))
->where('date', '=', $tanggal)
->get();
Here you will get date of the created_at
column at first and then compare inside where clause. 在这里,您将首先获取
created_at
列的日期,然后在where子句中进行比较。
Hope you understand. 希望你能理解。
You can used 你可以用
$absen = Absen::where(DB::raw("DATE_FORMAT(created_at,'%d/%M/%Y')"), '=', $tanggal)
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.