Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel查询中将字符串数据类型列转换为最新数据?_Php_Laravel_Postgresql_Eloquent_Casting - Fatal编程技术网

Php 如何在laravel查询中将字符串数据类型列转换为最新数据?

Php 如何在laravel查询中将字符串数据类型列转换为最新数据?,php,laravel,postgresql,eloquent,casting,Php,Laravel,Postgresql,Eloquent,Casting,我有一个laravel查询,在一个名为“schedule”的列中提取一年和一天。但是,该列声明为字符串数据类型,而不是日期。所以做whereYear('schedule',$year)不起作用,它说我必须使用显式类型转换。我已经搜索过了,但仍然没有找到答案。有一些建议,比如使用protect$dates和$cast-in模型,但仍然没有找到答案。有没有一种方法可以在我的控制器中进行如下所示的铸造?如果没有,我应该如何解决这个问题?请帮忙。非常感谢 $billDetails = Bill::whe

我有一个laravel查询,在一个名为“schedule”的列中提取一年和一天。但是,该列声明为字符串数据类型,而不是日期。所以做
whereYear('schedule',$year)
不起作用,它说我必须使用显式类型转换。我已经搜索过了,但仍然没有找到答案。有一些建议,比如使用protect$dates和$cast-in模型,但仍然没有找到答案。有没有一种方法可以在我的控制器中进行如下所示的铸造?如果没有,我应该如何解决这个问题?请帮忙。非常感谢

$billDetails = Bill::whereYear(CAST('schedule' AS DATE), $year)
                   ->whereDay(CAST('schedule' AS DATE), '<=', 15)
                   ->where('invalid', false)
                   ->orderBy('loan_id','ASC')
                   ->orderBy('schedule', 'ASC')
                   ->get();
$billDetails=Bill::whereYear(演员阵容(“日程安排”为日期),$year)

->whereDay(CAST(‘schedule’AS DATE),‘如果您以正确的格式存储日期,列类型应该无关紧要。MySQL
YEAR
函数可以很好地处理VARCHAR列。当您说不起作用时,您的意思是没有输出?whereYear应该起作用?whereYear(‘schedule’,$YEAR)它给出了什么确切的错误?我在我的帖子中添加了错误日志。请看一看。谢谢。你以前试过使用碳吗?处理日期时非常棒这是官方文档的链接
SQLSTATE[42883]: Undefined function: 7 ERROR: function pg_catalog.date_part(unknown, character varying) does not exist LINE 1: select * from "bills" where extract(year from "schedule") = ... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select * from "bills" where extract(year from "schedule") = 2021 and extract(day from "schedule") <= 15 and "invalid" = 0 order by "loan_id" asc, "schedule" asc)

SQLSTATE[42883]: Undefined function: 7 ERROR: function pg_catalog.date_part(unknown, character varying) does not exist LINE 1: select * from "bills" where extract(year from "schedule") = ... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select * from "bills" where extract(year from "schedule") = 2021 and extract(day from "schedule") <= 15 and "invalid" = 0 order by "loan_id" asc, "schedule" asc)