Can you explain why would you do something like that cause I never needed it?
Oct 4, 2020
7
Level 1
Calling Artisan::call('schedule:run') from a controller
Dear All,
I have created a console command that (for now) just outputs a log statement.
That command is scheduled every minute.
I have a controller endpoint (located at /scheduler/run) that performs an Artisan::call(); to the artisan schedule:run command.
Locally it works perfectly (laravel valet & nginx), on production (apache) however, nothing happens when hitting that endpoint... I do get the reply from my controller, but the scheduler is never triggered.
What is even more remarkable is that Artisan::call('my:ping') in my controller directly DOES work.
So it must have something to do with the scheduler...
My route:
Route::get('/scheduler/run', SchedulerController::class)->name('scheduler');
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Artisan;
class SchedulerController extends Controller
{
public function __invoke()
{
Artisan::call('schedule:run');
return response()->noContent();
}
}
My Kernel.php
<?php
namespace App\Console;
use App\Console\Commands\PingCommand;
use App\Console\Commands\RefreshTwikeyKey;
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 = [
PingCommand::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(PingCommand::class)->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
Please or to participate in this conversation.