I made a function in a Controller
and created a Command
in Artisan to run this function.
Follows:
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,
];
When I run php artisan cron_services
it gives me this error:
[Symfony \ Component \ Debug \ Exception \ FatalErrorException] Call to a member function getPath () on null
What am I missing?