![](/img/trans.png)
[英]How to get the current date and time in YYYY-MM-DD HH: MM? LARAVEL 4
[英]Laravel how to get current Time and Date value
我正在开发一个考勤管理系统。因此,我的主管要求我开发以下视图以获取考勤时间和日期值。
所有记录都需要根据受训者ID保存在数据库中。根据该视图,如果具有以上ID的复选框选中该复选框,然后按标记按钮,则必须将时间值和受训者ID准时保存在数据库中。
然后,如果将其标记一次,则Date值也需要保存在数据库中。
谁能为我建议相关的控制器功能?
这是相关的上述观点
<table class="table table-striped">
<thead>
<th>Trainee ID</th>
<th>Name with Initials</th>
<th>Time</th>
<th>Mark Here!</th>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td>{{ $item->trainee_id }}</td>
<td>{{ $item->name_with_initials }}</td>
<td>
<label><input type="checkbox" value=""> Time</label>
</td>
<td>
<a class="btn btn-info" href="Bankdetails/{{ $item->trainee_id }}">Mark Here</a>
</td>
</tr>
@endforeach
</tbody>
</table>
尝试这个
public function store(Request $request)
{
$request['time']=date("Y-m-d h:i:s a", time());
attendance::create($request->all());
return view('traineeattendance.attendanceo');
}
您可能要在这里使用Carbon
函数
参考一些文档: https : //github.com/briannesbitt/Carbon
Laravel附带有Carbon依赖项。
Carbon::now()
,如果需要,包括Carbon\\Carbon
命名空间。
编辑(用法和文档)
假设我想检索日期和时间并将其输出为字符串。
$mytime = Carbon\Carbon::now();
echo $mytime->toDateTimeString();
这将以Ymd H:i:s
的通常格式Ymd H:i:s
,其中有许多预先创建的格式,并且您不太可能需要用Carbon再次弄乱PHP日期时间字符串。
文档: https://github.com/briannesbitt/Carbon
: https://github.com/briannesbitt/Carbon
Carbon的字符串格式: http://carbon.nesbot.com/docs/#api-formatting
: http://carbon.nesbot.com/docs/#api-formatting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.