我目前正在使用laravel 5.4,我需要使用Carbon Class计算两个可用时间戳之间的差异。但是我收到此错误Call to a member function diffInHours() on string
您的任何见解都会对您有所帮助,谢谢:)
用户控制器
class UserController extends Controller
{
use EncryptDecrypt;
public function resetPassword($token)
{
$decryptTS = trim($this->decryptText($token));
$split = explode('-', $decryptTS, 2);
$userId = $split[0];
$timeStamp = $split[1];
$timeStamp1=Carbon::createFromTimestampUTC($timeStamp)->toDateTimeString();
$now = Carbon::now();
if($timeStamp1->diffInHours($now) <=24)
{
echo "valid URL";
}
else
{
echo "Invalid URL";
}
}
}
答案 0 :(得分:1)
尝试替换此行:
$timeStamp1=Carbon::createFromTimestampUTC($timeStamp)->toDateTimeString();
with:
$timeStamp1=Carbon::createFromTimestampUTC($timeStamp);
这第一个将返回字符串而不是碳对象