48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Core\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
class ModuleMakeController extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'module:controller {module} {controller}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Create a new controller for a module';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$moduleName = $this->argument('module');
|
|
$controllerName = $this->argument('controller');
|
|
$modulePath = modules_path($moduleName);
|
|
|
|
if (! is_dir($modulePath)) {
|
|
$this->error("Module [{$moduleName}] does not exist.");
|
|
|
|
return;
|
|
}
|
|
|
|
$controllerPath = "App\\Modules\\{$moduleName}\\Controllers\\{$controllerName}";
|
|
|
|
Artisan::call('make:controller', [
|
|
'name' => $controllerPath,
|
|
]);
|
|
|
|
$this->info("Controller [{$controllerName}] created successfully in module [{$moduleName}].");
|
|
}
|
|
}
|