[英]i have two fields named as created_at and updated_at(timestamps) and i want to search between these dates in my where clause
i want to take input date as a parameter and search between the dates that are given in input. 我想将输入日期作为参数,并在输入中给定的日期之间进行搜索。
Theses are the timestamps() provided by laravel to create the two fields as created_at and upated_at.I want to search between these dates that are given in created_at and updated_at but unable to find the data between these dates. 这些是laravel提供的创建stamped_at和upated_at这两个字段的时间戳()。我想在created_at和updated_at中给出的这些日期之间进行搜索,但是无法找到这些日期之间的数据。 Following is the code that i have create
以下是我创建的代码
` $startDate = $request->input('created_at');
$endDate = $request->input('updated_at');
->select()
->whereBetween('created_at','updated_at',[$startDate,$endDate])
->get();`
I think whereBetween
only accepts 2 parameters. 我认为
whereBetween
仅接受2个参数。 The first being the column name and the second the array with values to test. 第一个是列名,第二个是要测试值的数组。 Check: https://laravel.com/docs/5.5/queries#where-clauses
检查: https : //laravel.com/docs/5.5/queries#where-clauses
You would want something like: 您会想要类似:
->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])
The error: 错误:
Argument 2 passed to Illuminate\\Database\\Query\\Builder::whereBetween() must be of the type array
传递给Illuminate \\ Database \\ Query \\ Builder :: whereBetween()的参数2必须为数组类型
is because the second parameter of whereBetween()
is an array, and you pass a string 'updated_at'
here. 这是因为
whereBetween()
的第二个参数是一个数组,并且您在此处传递了字符串'updated_at'
。 So change it to like: 因此,将其更改为:
->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.