2 回答
TA贡献1811条经验 获得超4个赞
请试试这个,
public function store(Request $request)
{
Timesheet::create([
'in_time' => $request->get('in_time'),
'out_time' => $request->get('out_time'),
'break_out' => $request->get('break_out'),
'break_in' => $request->get('break_in'),
'user_id' => \Auth::user()->id,
]);
return redirect()->route('timesheet.create')
->with('success', 'Attendance marked successfully.');
}
TA贡献1877条经验 获得超1个赞
这听起来像是 AJAX 的工作。
步骤1:
为所有按钮添加通用类
// new time-btn class
<span style="float:right"><button type="submit" class="btn btn-success btn-sm
btn time-btn">Mark</button></span>
第2步:
获取数据并使用 AJAX 发送(使用 jquery):
$(document).on('click', '.time-btn', function(e) {
e.preventDefault();
// get value of first input before the button
var time = $(this).prev('input').val();
// get input name
var name = $(this).prev('input').attr('name')
// validate time if necessary
$.ajax({
url: '/time/store', // insert route url here
type: 'POST',
data: {time: time, name: name},
success: function( response ) {
response = JSON.parse( response );
// add tick mark to button here
},
error: function (xhr, status, error) {
console.log( xhr.responseText );
}
});
});
第 3 步:
更新控制器
public function store(Request $request)
{
Timesheet::create([
'in_time' => request('name') == 'in_time' ? request('time') : null,
'out_time' => request('name') == 'out_time' ? request('time') : null,
// do the same for tother
...
'user_id' => Auth::user()->id,
]);
return redirect()->route('timesheet.create')
->with('success', 'Attendance marked successfully.');
}
添加回答
举报