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)
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.
'providers' => [
....
Irfa\RajaOngkir\RajaOngkirServiceProvider::class,
];
'aliases' => [
....
'RajaOngkir' => Irfa\RajaOngkir\Facades\Ongkir::class,
],
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 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
Open console/cmd and run
php artisan raja-ongkir:cache all
Open console/cmd and run
php artisan raja-ongkir:cache city
Open console/cmd and run
php artisan raja-ongkir:cache province
Open console/cmd and run
php artisan raja-ongkir:cache clear
Clear old cache and create latest cache.
Open console/cmd and run
php artisan raja-ongkir:cache refresh
use RajaOngkir;
$get = RajaOngkir::province()->get();
foreach($get as $prov)
{
echo $prov->province_id."<br>"; // value = 1
echo $prov->province."<br>";// value = Bali
}
$get = RajaOngkir::find(['province_id' => 1])->province()->get();
echo $get->province_id."<br>"; // value = 1
echo $get->province."<br>";// value = Bali
$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
}
$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
}
$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)
}
$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>";
}
}
- Fork it (https://github.com/irfaardy/raja-ongkir/fork)
- Commit your changes (
git commit -m 'New Feature'
) - Push to the branch (
git push origin master
) - 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.
- Lakukan fork di (https://github.com/irfaardy/raja-ongkir/fork)
- Commit perubahan yang anda lakukan (
git commit -m 'Fitur Baru'
) - Push ke branch master (
git push origin master
) - Buat Pull Request baru
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.