Jason Jason - 1 month ago 5
PHP Question

Show message if update time is less tha 8 hours in blade template

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
?

Answer

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
Comments