byos_laravel/app/Console/Commands/ScreenGeneratorCommand.php
2025-05-12 18:44:22 +02:00

45 lines
1,007 B
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\GenerateScreenJob;
use Illuminate\Console\Command;
class ScreenGeneratorCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'trmnl:screen:generate {deviceId=1} {view=trmnl}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate a screen for a terminal device';
/**
* Execute the console command.
*/
public function handle()
{
$deviceId = $this->argument('deviceId');
$view = $this->argument('view');
try {
$markup = view($view)->render();
} catch (\Throwable $e) {
$this->error('Failed to render view: '.$e->getMessage());
return 1;
}
GenerateScreenJob::dispatchSync($deviceId, null, $markup);
$this->info('Screen generation job finished.');
return 0;
}
}