0
I have a slide show of images where the images registered in the database appear. The table is called events. In this table there is a field called end date, which would refer to the end of the event date, and I also have a field called status, where he’s kind of Boolean that when she’s like true is active on the slide. What I need for a service to listen to, when the current date (date(’d)) is no longer equal to the field date end date that it be disabled the status field == false. How would you accomplish this feat? I was doing so see:
$evento = Evento::whereDay('data_fim', '<=' ,date('d'))->first();
if($evento){
$evento->status = false;
$evento->save();
}
The more I think this is very gambiarra. There is a smarter way to do the same. I would like to learn from services in Laravel. I do not know very well. I ask you to guide me.
You want to always check before saving?
– Jéf Bueno
I don’t want when the event date passes the current date that it deactivates a table field
– Natan Melo
Right, but when?
– Jéf Bueno
Let’s assume the date of the event and day 28/09/2017 to day 30/09/2017 .
– Natan Melo
So I did so. I don’t know if this and gambiarra anymore works hehehe. Would you like your opinion: $expire = Event::whereDay('data_end', '<' ,date(’d'))->Where('status' , true)->Where('expire', true)->first(); // dd($expire); if(isset($expire) and $expire->Count() >= 1 ){ $expire->expire = false; $expire->save(); }
– Natan Melo