irfa/raja-ongkir

"Laravel Raja Ongkir Package"

Installs: 1 120

Dependents: 0

Suggesters: 0

Security: 0

Stars: 13

Watchers: 3

Forks: 10

Open Issues: 1

Type:package

v1.33 2020-06-03 08:08 UTC

This package is auto-updated.

Last update: 2024-04-21 17:37:02 UTC


README

Scrutinizer Code Quality Build Status Latest Stable Version PHP

Buy Me A Coffee ko-fi

Package ini berguna untuk mengecek biaya ongkos kirim dari kurir, package ini dapat digunakan di Laravel 5/6/7 atau PHP Native. (untuk saat ini hanya mendukung tipe akun starter)

🛠️ 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.

🛠️ 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 and add this 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 in config/irfa/rajaongkir.php or project_name/.env.
This function currently only supports the Laravel Framework

Cache support : database and file
( if you don't want to use cache you can set it to null )

Migrating table city and provinsi

If you want to use database cache, you must run migrate first.

php artisan migrate

Caching Province,Sub-District and City


Open console/cmd and run

php artisan raja-ongkir:cache all

Caching City


Open console/cmd and run

php artisan raja-ongkir:cache city

Caching Province


Open console/cmd and run

php artisan raja-ongkir:cache province

Clear Cache


Open console/cmd and run

php artisan raja-ongkir:cache clear

Refresh Cache


Clear old cache and create latest cache.
Open console/cmd and run

php artisan raja-ongkir:cache refresh

💻 Usage

  use RajaOngkir;

Retrieve all province

 $get = RajaOngkir::province()->get();
 foreach($get as $prov)
 {
	echo $prov->province_id."<br>"; // value = 1
	echo $prov->province."<br>";// value = Bali
 }

Search province

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

Retrieve all City

$get = RajaOngkir::city()->get();
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
}

Retrieve all city in province

    $get = RajaOngkir::find(['province_id' => 1])->city()->get();
    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
     }

Retrieve courier

  $get = RajaOngkir::find(['origin'=>1,'destination'=>2,'weight'=>1000,'courier' => 'jne'])
	 ->courier()->get();
  foreach($get as $city)
  {
	echo $city->code."<br>"; // value = jne
	echo $city->name."<br>";// value = Jalur Nugraha Ekakurir (JNE)
  }

Retrieve cost courier

 $params = ['origin'=>1,'destination'=>2,'weight'=>1000,'courier' => 'jne'
			   ];
     $get = RajaOngkir::find($params)->costDetails()->get();
     foreach($get as $cost)
     {
	echo "Courier Name: ".$cost->service."<br>";
	echo "Description: ".$cost->description."<br>";
	 foreach($cost->cost as $detail)
	 {
		echo "Harga: ".$detail->value."<br>";
		echo "Estimasi: ".$detail->etd."<br>";
		echo "Note: ".$detail->note."<br>";
		echo "<hr>";
	 }
      }

How to Contributing?

  1. Fork it (https://github.com/irfaardy/raja-ongkir/fork)
  2. Commit your changes (git commit -m 'New Feature')
  3. Push to the branch (git push origin master)
  4. Create a new Pull Request

if you found bug or error, please post here https://github.com/irfaardy/raja-ongkir/issues so that they can be maintained together.

Bagaimana cara berkontribusi?

  1. Lakukan fork di (https://github.com/irfaardy/raja-ongkir/fork)
  2. Commit perubahan yang anda lakukan (git commit -m 'Fitur Baru')
  3. Push ke branch master (git push origin master)
  4. Buat Pull Request baru

Issue

If you found issues or bug please create new issues here https://github.com/irfaardy/php-gacha/issues/new

Jika anda menemukan bug atau error silahkan posting disini https://github.com/irfaardy/raja-ongkir/issues agar dapat diperbaiki bersama-sama.