I want to implement a logic in my laravel backend using the date of a post.
The example is as follows:
A user creates an article, it contains title, content, image, its user owner and its publication date. It turns out that the user published this article but had one or more spelling errors and wants to edit it, but he realized hours later, he would like to avoid this. , I would like to compare the date in minutes with Laravel using Carbon or some native php function, making it, through an if statement, tell me that it compares if the date of the article has been greater than 30 minutes, said article cannot be edited, something like this:
if($article->create_at > 30min){
return abort(403, 'No tienes permisos para editar ya este artículo');
}
With Carbon there are several ways to do it, one of them is with
diffInMinutes()
, taking as reference the date of creation of the article:More information and ideas in the Carbon documentation: http://carbon.nesbot.com/docs/#api-difference