Skip to content

Commit

Permalink
add doc and change Readme for support publish on lumen
Browse files Browse the repository at this point in the history
  • Loading branch information
cacing69 committed Aug 24, 2019
1 parent 13fe785 commit 69fb90a
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -98,4 +123,4 @@ $regency->hasVillageId([6101050014, 6101040025, 6101060023, 6101020014]);
// Get Desa/Kelurahan dari sebuah Kecamatan
$villages = $district->villages;
```
```
102 changes: 102 additions & 0 deletions src/IndoRegionPublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/*
* This file is part of the IndoRegion package.
*
* (c) Ibnul Mutaki <cacing69 | [email protected]>
*
*/

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/");
}
}

0 comments on commit 69fb90a

Please sign in to comment.