Laravel automatic update on database
Ad
I created a membership system using Laravel and I would like to know how automatically update the "active" column when the date is expired.
My table :
membership(id, dateBegin, dateEnd, active)
when (dateEnd > NOW) active = 0
Thank's
Ad
Answer
Ad
Since your using Laravel you could make use of its Task Scheduling to accomplish this. See the Defining Schedules section of the documentation.
Based on the example given you could do something like
<?php
namespace App\Console;
...
class Kernel extends ConsoleKernel
{
...
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
DB::table('membership')->whereRaw('dateEnd > now()')->update(['active' => 0]);
})->daily();
}
}
I haven't tested the above but it should work as you require.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad