From 69fb90a39487454eef367491e5729bdcf7564a06 Mon Sep 17 00:00:00 2001 From: cacing69 Date: Sun, 25 Aug 2019 02:17:49 +0700 Subject: [PATCH] add doc and change Readme for support publish on lumen --- README.md | 27 +++++++- src/IndoRegionPublishCommand.php | 102 +++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/IndoRegionPublishCommand.php diff --git a/README.md b/README.md index 601ad17..400c417 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,31 @@ Jalankan perintah dibawah di Command Line: ``` php artisan vendor:publish ``` + +### Lumen +Untuk melakukan publish dilumen, tambahkan IndoRegionPublishCommand pada file + +``` +app/Console/Kernel.php +``` +``` +use AzisHapidin\IndoRegion\IndoRegionPublishCommand; // tambahkan baris ini +... + +class Kernel extends ConsoleKernel +{ + protected $commands = [ + IndoRegionPublishCommand::class // tambahkan baris ini + ]; +} +``` + +Lalu jalankan perintah dibawah ini + +``` +php artisan indoregion:publish +``` +--- Saat perintah diatas dijalankan, maka akan muncul pilihan list providers atau tags yang bisa di-publish. Silahkan pilih ```Provider: AzisHapidin\IndoRegion\IndoRegionServiceProvider``` untuk menyalin beberapa file yang akan kita butuhkan yaitu: @@ -98,4 +123,4 @@ $regency->hasVillageId([6101050014, 6101040025, 6101060023, 6101020014]); // Get Desa/Kelurahan dari sebuah Kecamatan $villages = $district->villages; -``` \ No newline at end of file +``` diff --git a/src/IndoRegionPublishCommand.php b/src/IndoRegionPublishCommand.php new file mode 100644 index 0000000..a13af29 --- /dev/null +++ b/src/IndoRegionPublishCommand.php @@ -0,0 +1,102 @@ + + * + */ + +namespace AzisHapidin\IndoRegion; + +use Illuminate\Console\Command; +use Illuminate\Support\Facades\File; + +class IndoRegionPublishCommand extends Command +{ + /** + * The console command signature. + * + * @var string + */ + protected $signature = 'indoregion:publish'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Publish IndoRegion assets from vendor packages'; + + /** + * Compatiblity for Lumen 5.5. + * + * @return void + */ + public function handle() + { + $this->fire(); + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + $this->publishModels(); + $this->publishMigrations(); + $this->publishSeeds(); + + $this->info("Publishing IndoRegion complete"); + } + + + /** + * Publish the directory to the given directory. + * + * @param string $from + * @param string $to + * @return void + */ + protected function publishDirectory($from , $to) + { + $exclude = array('..' , '.' , '.DS_Store'); + $source = array_diff(scandir($from) , $exclude); + + foreach ($source as $item) { + $this->info("Copying into : " . $to . $item); + File::copy($from . $item , $to . $item); + } + } + + /** + * Publish model. + * + * @return void + */ + protected function publishModels() + { + $this->publishDirectory(__DIR__.'/database/models/', app()->path()."/Models/"); + } + + /** + * Publish migrations. + * + * @return void + */ + protected function publishMigrations() + { + $this->publishDirectory(__DIR__.'/database/migrations/', app()->databasePath()."/migrations/"); + } + + /** + * Publish seeds. + * + * @return void + */ + protected function publishSeeds() + { + $this->publishDirectory(__DIR__.'/database/seeds/', app()->databasePath()."/seeds/"); + } +}