bronanza / laravel-ongkir
This package provides the use of raja ongkir API
Installs: 85
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/bronanza/laravel-ongkir
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: ~4.1
This package is not auto-updated.
Last update: 2025-10-31 22:38:07 UTC
README
Laravel ongkir provide the use of raja ongkir API in Laravel 5.
Contents
Installation
- To install laravel-ongkir, add the following code to composer.json. Then run
composer update:
"bronanza/laravel-ongkir": "dev-master"
- Open your
config/app.phpand add the following code to provider:
Bronanza\LaravelOngkir\OngkirServiceProvider::class,
- Run the command below to publish package config file
config/ongkir.php
php artisan vendor:publish
- You can fill
api keyfor laravel ongkir inconfig/ongkir.php
<?php return [ 'api' => 'http://api.rajaongkir.com/starter', 'apiKey' => '12kasjdaksdqpwepqwoepqwoe', 'originCityId' => 151, // Jakarta Barat Based on RajaOngkir API 'couriers' => [ 'jne' => 'JNE', 'tiki' => 'TIKI' ] ];
Usage
- Add the following code in your class file:
use Bronanza\LaravelOngkir\Ongkir;
- Now you can use Laravel-Ongkir:
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Bronanza\LaravelOngkir\Ongkir; class TestController extends Controller { private $laravelOngkir; public function __construct(Ongkir $ongkir) { $this->laravelOngkir = $ongkir; } public function getAllAvailableProvinces() { return $this->laravelOngkir->getAllAvailableProvinces(); } public function getAllAvailableCities() { return $this->laravelOngkir->getAllAvailableCities(); } public function getAvailableCities() { return $this->laravelOngkir->getAvailableCities("5"); } public function getCosts() { return $this->laravelOngkir->getCosts("501", "114", 1700, "jne"); } }
Explanation
getAllAvailableProvinces()— use this method to get all available provinces in Indonesia.getAllAvailableCities()— use this method to get all available cities in Indonesia.getAvailableCities()— use this method to get available cities for the given province code. This method need 1 paramater:stringprovinceCode- Province ID in Indonesia
getCosts()— use this method to get shipment cost based on weight and location. This method need 4 parameter:stringoriginId- city originstringrajaongkirCityId- city destinationintweight- shipment weight in gramstringcourier- the available courier code:jne,pos,tiki.