Skip to content
IRFA edited this page Feb 23, 2020 · 1 revision

🚀Raja Ongkir Laravel Package

GitHub license Support me

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 ^_^.

🛠️ Installation with Composer

composer require irfa/raja-ongkir

You can get Composer here


🛠️ PHP Native Setup

  <?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.


🛠️ Laravel Setup

Add to config/app.php

'providers' => [
      ....
         Irfa\RajaOngkir\RajaOngkirServiceProvider::class, 
     ];

Add to config/app.php

'aliases' => [
         ....
    'RajaOngkir' => Irfa\RajaOngkir\Facades\Ongkir::class,

    ],

Publish Vendor

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

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

Caching Province and City


Open console/cmd and run
php artisan raja-ongkir:cache

Caching City


Open console/cmd and run
php artisan raja-ongkir:city-cache

Caching Province


Open console/cmd and run
php artisan raja-ongkir:prov-cache

Clear Cache


Open console/cmd and run
php artisan raja-ongkir:clear

💻 Usage

  use RajaOngkir;

Retrieve all province

 $get = RajaOngkir::getProvince();
 foreach($get as $prov):

	echo $prov->province_id."<br>"; // value = 1
	echo $prov->province."<br>";// value = Bali
	
	
endforeach;

Search province

   $get = RajaOngkir::find(['province_id' => 1])->getProvince();
     
	echo $get->province_id."<br>"; // value = 1
	echo $get->province."<br>";// value = Bali

Retrieve all City

$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;

Retrieve all city in province

$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;

Retrieve courier

  $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;

Retrieve cost courier

 $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;