0
I did a job on a Controller
and created a Command
in the 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 to perform php artisan cron_services
give me that mistake:
[Symfony Component Debug Exception Fatalerrorexception] Call to a Member Function getPath() on null
What am I missing ?
It’s to bring up a list. Laravel 5.1.
– Diego Souza
So hard that I already solved this with a Service Provider. I was just taking a break in the question. But for the purpose of answering, I put a
dd(1)
before calling Empresarating and he killed the code right there.– Diego Souza
No bro. I don’t want to list the records. I just do a search, ask if there is a record. If yes, I already send an update.
– Diego Souza