Created
January 5, 2018 12:10
-
-
Save takeokunn/d4aa6adf07506eaddef4676012fec0cb to your computer and use it in GitHub Desktop.
銀行/支店一覧を取得コード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
namespace Hoge; | |
class FetchBanks | |
{ | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function handle(): void | |
{ | |
// initialize | |
// DB::table('base_banks')->truncate(); | |
// DB::table('base_bank_branches')->truncate(); | |
$base_url = 'https://bank.teraren.com/banks.json'; | |
for ($loop = 1; $loop < 28; $loop++) { | |
// fetch bank data | |
$url = $base_url . '?page=' . $loop; | |
$json = file_get_contents($url); | |
$banks = json_decode($json, true); | |
foreach ($banks as $bank) { | |
// create bank | |
$this->bank->create($bank['code'], $bank['kana'], $bank['name']); | |
var_dump($bank['kana']); | |
// fetch bank_branch data by bank | |
$json = file_get_contents($bank['branches_url']); | |
$branches = json_decode($json, true); | |
foreach ($branches as $branch) { | |
var_dump($branch['kana']); | |
// create bank_branch | |
$this->bank->createBranch($bank['code'], $branch['code'], $branch['kana'], $branch['name']); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment