Maybe is something simple but I have one submit form which I want to restrict so user should be able to update it once per 8 hours.
I have updated_at
column in database table which store last update time in timestamp
: 2016-10-21 09:56:13
Now in my blade template I've tried to check like this
@if($time->updated_at < 8 hour)
// show message to come back after 8 hours
@else
// show the form
@endif
I've got
'syntax error, unexpected 'hour' (T_STRING)'
I know why I got this but I don't how to make the if... do I need to convert current time and then how to present 8 hours? Like 60*60*8
?
Assuming your updated_at
is using Laravel's default timestamps
@if((time() - strtotime($time->updated_at)) < 28800)
// show message to come back after 8 hours
@else
// show the form
@endif
if you are using larvel timestamps than updated_at is always the object of carbon so you can use carbon to get difference between current date/time and your model updated_at
@if(Carbon\Carbon::now()->diffInHours($time->updated_at) > 8)
//time difference is greater than 8
@else
// time difference is less than or equal to 8 hours
@endif