我是 Laravel 5 的初学者。我有一个表:用户,其中包含 CreateDate、Type 和 Channel 列。
我有一个用户列表,我在视图中选择:Trans StartDate、Trans EndDate、Type 和 Channel。
我想展示:特拉斯StartDate < CreateDate < Trans EndDate
与类型和通道。name="time_start", "time_end", "type", "channel"
.
我的路线:
Route::post('user', 'CSKHController@index');
我的控制器:
public function index() {
$start = Input::get ( 'time_start' );
$end = Input::get ( 'time_end' );
$articles = KhachHang::all()->whereBetween('CreateDate', [$start, $end])->get();
return view('admin/layouts/test', compact('stt','article'))->withDetails($articles);
}
请帮帮我!
拉拉维尔 5.*
这是我如何在 a 中使用 eloquent 的一个例子拉拉维尔 5.6项目。
my-view.blade.php
简化的 html 形式:
<form action="my-route" method="POST">
{{ csrf_field() }}
<input type="date" name="from">
<input type="date" name="to">
<button type="submit">Submit</button>
</form>
我的控制器.php
use Illuminate\Support\Carbon;
// ...
$request->validate([
'from' => 'required|date',
'to' => 'required|date',
]);
$from = Carbon::parse($request->from)
->startOfDay() // 2018-09-29 00:00:00.000000
->toDateTimeString(); // 2018-09-29 00:00:00
$to = Carbon::parse($request->to)
->endOfDay() // 2018-09-29 23:59:59.000000
->toDateTimeString(); // 2018-09-29 23:59:59
$models = Model::whereBetween('created_at', [$from, $to])->get();
// do whatever you want with the query results...
其他资源
带有 whereBetween 的日期范围 https://laracasts.com/discuss/channels/eloquent/daterange-with-wherebetween#reply=283013
将碳日期转换为 mysql 时间戳 https://stackoverflow.com/a/43012671/4325011
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)