Laravel update status of records

2

Good I need to automatically update the status of my budget to "Due" when the expiration date has already passed

my budget table:

id          
fecha_emision           
status          
total           
fecha_expiracion            
cod_usuario         
cod_cliente         
cod_contacto            
codigo_presupuesto          
nota            
respaldo            
descripcion         
validez
    
asked by Jorge Ortiz 03.07.2017 в 01:47
source

1 answer

1

To achieve that you need to configure and use the Laravel cron: link

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

Next you create a command that will perform the status update: link

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ExpirarPresupuesto extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'presupuesto:expirar';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Marca los presupuestos como expirados cuando pasa dicha fecha';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();

        // ...
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // *****agrega aquí el código que cambia el estado de los presupuestos expirados*****
    }
}

Finally, add the command to the configuration of the schedules: link

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\ExpirarPresupuesto::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('presupuesto:expirar')
            ->dailyAt('04:00');
    }
}
    
answered by 03.07.2017 / 01:57
source