I have a problem with a Laravel scheduler.
In practice, if I write all the code in a controller with a command it works, but if I make the scheduler do it it gives me fail "NUL" 2>&1
I always work with the scheduler and this error has never come up
given that the scheduler works up to a certain point because the zip file is created but then it is not saved in the s3 storage in the controller everything works thank you very much I hope you can help me..
Code commands :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
use ZipArchive;
class Backup extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'backup:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Backup foto caricate nell app';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$zip = new ZipArchive;
$azienda = User::value('azienda');
$fileName = time() . $azienda . ".zip";
if ($zip->open(public_path($fileName), ZipArchive::CREATE) === TRUE) {
$files = File::files(public_path('/images/images'));
foreach ($files as $key => $value) {
$relativeNameInZipFile = basename($value);
$zip->addFile($value, $relativeNameInZipFile);
}
$zip->close();
};
Storage::disk('s3')->put('public' . $fileName, fopen($fileName, 'r'));
//return Command::SUCCESS;
}
}
Kernel :
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected $commands = [
Commands\Backup::class
];
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:name')->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}