samedi 25 janvier 2020

Laravel filter posts list using whereBetween

I've a posts list with a column "created_at". I want to retrieve ONLY posts that are max 10 minutes old (based on when they have been created). I've seen tons of examples about how to use whereBetween, but every time they pass the two values through some inputs or hardcoding them.

There is a way, except from loop my query for every single post (and put an If), to write something like this in Laravel:

$posts->whereBetween('created_at', [$now_date, $current_post_created_at]);

Where I pass as first parameter "now", and as second parameter the created_at column value of the current post I'm retrieving from DB.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2RojeRP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire