1
0
Fork 0
mirror of https://github.com/archtechx/airwire.git synced 2025-12-12 10:44:03 +00:00

register component in AppServiceProvider automatically

This commit is contained in:
lukinovec 2021-05-23 00:40:12 +02:00
parent 20f8881897
commit de1c1faaa7
2 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,12 @@
<?php
namespace Airwire\Commands;
use Illuminate\Support\Str;
class Component {
public static function register(string $name)
{
$service_provider = base_path() . "\app\Providers\AppServiceProvider.php";
file_put_contents($service_provider, preg_replace('/register[(][)][\s\S].*/', "register() {\n\t\tAirwire::component('" . Str::snake($name) . "', {$name}::class);", file_get_contents($service_provider)));
}
}

View file

@ -33,9 +33,7 @@ class ComponentCommand extends Command
}
PHP);
$this->line("✨ Component app/Airwire/{$name}.php has been created!\n");
$this->warn("🚧 Don't forget to register the component! Add the following line to AppServiceProvider:");
$this->line("\n\n Airwire::component('" . Str::snake($name) . "', {$name}::class);\n\n");
Component::register($name);
$this->line("✨ Component app/Airwire/{$name}.php has been created and registered!\n");
}
}