-
-
Notifications
You must be signed in to change notification settings - Fork 10
Home
IRFA edited this page Feb 23, 2020
·
1 revision
Package ini berguna untuk mengecek biaya ongkos kirim dari kurir, package ini dapat digunakan di Laravel 5 / 6 atau PHP Native.
Silahkan jika anda ingin ikut mengembangkan package ini ^_^.
composer require irfa/raja-ongkir
You can get Composer here
<?php
require "vendor/autoload.php";
use Irfa\RajaOngkir\Ongkir\Ongkir as RajaOngkir;
....
Configuration File
Config location : vendor/irfa/raja-ongkir/config/config.php
<?php
$config = [
'account_type' => 'your-account-type',
'api_key' => 'your-api-key',
];
You can get API key in Raja Ongkir.
Account type supported : starter, basic, and pro.
'providers' => [
....
Irfa\RajaOngkir\RajaOngkirServiceProvider::class,
];
'aliases' => [
....
'RajaOngkir' => Irfa\RajaOngkir\Facades\Ongkir::class,
],
php artisan vendor:publish --tag=raja-ongkir
Open .env file add line
....
RAJAONGKIR_ACCOUNT_TYPE = starter
RAJAONGKIR_API_KEY = your-api-key
RAJAONGKIR_PROV_TABLE=ro_province
RAJAONGKIR_CITY_TABLE=ro_city
RAJAONGKIR_CACHE=database
Caching is useful for loading city and province faster🚀.
You can change cache type ini config/irfa/rajaongkir.php.
Cache support : database and file
Migrating table city and provinsi
If you want to use database cache, you must run migrate first.
php artisan migrate
Open console/cmd and run
php artisan raja-ongkir:cache
Open console/cmd and run
php artisan raja-ongkir:city-cache
Open console/cmd and run
php artisan raja-ongkir:prov-cache
Open console/cmd and run
php artisan raja-ongkir:clear
use RajaOngkir;
$get = RajaOngkir::getProvince();
foreach($get as $prov):
echo $prov->province_id."<br>"; // value = 1
echo $prov->province."<br>";// value = Bali
endforeach;
$get = RajaOngkir::find(['province_id' => 1])->getProvince();
echo $get->province_id."<br>"; // value = 1
echo $get->province."<br>";// value = Bali
$get = RajaOngkir::getCity();
foreach($get as $city):
echo $city->city_id."<br>"; // value = 17
echo $city->province_id."<br>";// value = 1
echo $city->province."<br>";// value = Bali
echo $city->type."<br>"; // value = Kabupaten
echo $city->city_name."<br>"; // value = Badung
echo $city->postal_code."<br>"; // value = 80351
endforeach;
$get = RajaOngkir::find(['province_id' => 1])->getCity();
foreach($get as $city):
echo $city->city_id."<br>"; // value = 17
echo $city->province_id."<br>";// value = 1
echo $city->province."<br>";// value = Bali
echo $city->type."<br>"; // value = Kabupaten
echo $city->city_name."<br>"; // value = Badung
echo $city->postal_code."<br>"; // value = 80351
endforeach;
$get = RajaOngkir::find(['origin'=>1,
'destination'=>2,
'weight'=>1000,//1000gr
'courier' => 'jne'
])
->getCourier();
foreach($get as $city):
echo $city->code."<br>"; // value = jne
echo $city->name."<br>";// value = Jalur Nugraha Ekakurir (JNE)
endforeach;
$params = ['origin'=>1,'destination'=>2,'weight'=>1000,'courier' => 'jne'
];
$get = RajaOngkir::find($params)->getCostDetails();
foreach($get as $cost):
echo "Service: ".$cost->service."<br>";
echo "Description: ".$cost->description."<br>";
foreach($cost->cost as $detail):
echo "Value: ".$detail->value."<br>";
echo "Estimasi: ".$detail->etd."<br>";
echo "Note: ".$detail->note."<br>";
echo "<hr>";
endforeach;
endforeach;