mirror of
https://github.com/archtechx/airwire.git
synced 2026-02-04 05:54:04 +00:00
Merge pull request #10 from lukinovec/register_component
Register component in AppServiceProvider automatically
This commit is contained in:
commit
22d028aefd
1 changed files with 20 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Airwire\Commands;
|
namespace Airwire\Commands;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
|
@ -33,9 +34,25 @@ class ComponentCommand extends Command
|
||||||
}
|
}
|
||||||
PHP);
|
PHP);
|
||||||
|
|
||||||
$this->line("✨ Component app/Airwire/{$name}.php has been created!\n");
|
$this->register($name);
|
||||||
|
}
|
||||||
|
|
||||||
$this->warn("🚧 Don't forget to register the component! Add the following line to AppServiceProvider:");
|
protected function register($name)
|
||||||
$this->line("\n\n Airwire::component('" . Str::snake($name) . "', {$name}::class);\n\n");
|
{
|
||||||
|
try {
|
||||||
|
$path = app_path('Providers/AppServiceProvider.php');
|
||||||
|
|
||||||
|
$snake = Str::snake($name);
|
||||||
|
|
||||||
|
file_put_contents($path, str_replace(
|
||||||
|
"function boot()\n {",
|
||||||
|
"function boot()\n {\n \Airwire\Airwire::component('{$snake}', {$name}::class);",
|
||||||
|
file_get_contents($path)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->line("✨ Component app/Airwire/{$name}.php has been created and registered!");
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->error('The component could not be registered. Please check your app/Providers/AppServiceProvider.php');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue