我想計算時差並將其插入到數據庫中...我的模型名稱是「預訂」,開始時間和結束時間將從用戶輸入..and total_duration將從這兩個計算並將插入到數據庫中...我使用這些代碼...但不會working.this是我的控制器。laravel時間計算從用戶輸入
<?php
/*namespace App\booking;*/
use Carbon\Carbon;
namespace App\Http\Controllers;
use App\booking;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;
class RoombookController extends Controller
{
public function showreport(Request $request)
{
/* dd($request->all());
*/ $time= Carbon.now();
$booking = new booking;
$booking->bookdate = $request->input('bookdate');
$booking->roomname = $request->input('roomname');
//echo $datefrom;
$booking->starttime =$startTime= $request->input('starttime');
$booking->endtime = $finishTime=$request->input('endtime');
$booking->purpose = $request->input('Purpose');
//echo $dateto;
$time->sTime = Carbon::parse($startTime);
$time->fTime = Carbon::parse($finishTime);
$time->total_time = $fTime->diffForHumans($sTime);
$booking->total_duration = $time->total_time;
$booking->save();
}
}
thnx,它完全工作:D – incorporeal