Fiz uma função num Controller
e criei um Command
no Artisan para rodar essa função.
Segue:
Controller
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\EmpresaRating;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class CronController extends Controller
{
public static function fireCron(){
$ratings = EmpresaRating::where('quarentena', '=', 1)
->whereRaw("DATE_FORMAT(data_publicacao, '%Y-%m-%d') = '".date('Y-m-d')."'");
if($ratings->exists()){
$ratings->update(['quarentena' => 0]);
}
}
}
CronCommand
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Http\Controllers\Controller;
class CronCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cron_services';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cron para atualizar avaliações que estão em quarentena após 7 dias.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$controller = app()->make('App\Http\Controllers\CronController');
app()->call([$controller, 'fireCron'], []);
}
}
Kernel
protected $commands = [
\App\Console\Commands\Inspire::class,
\App\Console\Commands\CronCommand::class,
];
Quando execute php artisan cron_services
me dá esse erro:
[Symfony\Component\Debug\Exception\FatalErrorException] Call to a member function getPath() on null
O que eu estou errando ?
dd(1)
antes de chamar o EmpresaRating e ele matou o código ali mesmo.