Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Development/TemplateRender.php
<?php | <?php | ||||
namespace App\Console\Development; | namespace App\Console\Development; | ||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
class TemplateRender extends Command | class TemplateRender extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'template:render {template}'; | protected $signature = 'template:render {template} {--html} {--pdf}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = "Render a email template."; | protected $description = "Render a email template."; | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$template = $this->argument('template'); | $template = $this->argument('template'); | ||||
$template = str_replace('/', '\\', $template); | $template = str_replace("/", "\\", $template); | ||||
$class = '\\App\\' . $template; | $class = "\\App\\{$template}"; | ||||
echo $class::fakeRender(); | // Invalid template, list all templates | ||||
if (!class_exists($class)) { | |||||
$this->info("Invalid template name. Available templates:"); | |||||
foreach (glob(app_path() . '/Documents/*.php') as $file) { | |||||
$file = basename($file, '.php'); | |||||
$this->info("Documents/$file"); | |||||
} | |||||
foreach (glob(app_path() . '/Mail/*.php') as $file) { | |||||
$file = basename($file, '.php'); | |||||
$this->info("Mail/$file"); | |||||
} | |||||
return 1; | |||||
} | |||||
$mode = 'html'; | |||||
if (!empty($this->option('pdf'))) { | |||||
$mode = 'pdf'; | |||||
} | |||||
echo $class::fakeRender($mode); | |||||
} | } | ||||
} | } |