In laravel (v9) project i try to launch some bash command, like this
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Carbon\Carbon;
class SaveLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'eraselog';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Save current log and erase old log';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$copy = new Process(['cp storage/logs/laravel.log storage/logs/laravel_new.log']);
$erase = new Process([' > storage/logs/laravel.log']);
$copy->run();
$erase->run();
}
}
The problem: Commands doesn't work. Maybe this ins´t the proper way to launch this commands. So, anybody shows what's the right way?