hunterhawley
3 months ago

Comparing Dates in Where Clause (Twist: date stored at string)

Posted 3 months ago by hunterhawley

I've got a model that has a column: date_revoked (this is stored as a string)

After this date is passed, a user is no longer supposed to be able to access a certain page.

I'd like to restrict this access in the controller.

Currently, I can do a janky partial fix by putting this inside of a foreach in my view

@if(strtotime($filmShareIn->date_revoked) >= strtotime(date('Y-m-d')))

But when I try the following in the controller, I get no filtering:

->where('date_revoked', '>=', Carbon::now())

I know I may have really just screwed up by storing it as a string, but if anyone can get me out of this jam, it is my friends at Laracasts.

Thanks!

Please sign in or create an account to participate in this conversation.