I have a table called events and events expire. if their dates and time is up how do i check in my controller if the dateTime field from and to are up if that event time is up i want to set the expired field to 1
public function up()
{
Schema::create(‘club_events’, function (Blueprint $table) {
$table->increments(‘id’);
$table->string(‘event_name’);
$table->string(‘description’);
$table->boolean(‘special_events’);
$table->decimal(‘event_price’);
$table->dateTime(‘from’)->nullable();
$table->dateTime(‘to’)->nullabe();
$table->boolean(‘expired’)->nullable();
$table->integer(‘club_id’)->unsigned();
$table->timestamps();
$table->foreign(‘club_id’)
->references(‘id’)->on(‘club’)
->onDelete(‘cascade’);
});
}
You would compare it to the current datetime like:
if (now()->gte($clubEvent->to)) {
// the event is expired
} else {
// not expired
}
Here are the Carbon comparison functions.
Update the expired field like:
$clubEvent->update([
'expired' => now()->gte($clubEvent->to)
]);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments