PHP code example of pewe / laravel-rajaongkir

1. Go to this page and download the library: Download pewe/laravel-rajaongkir library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pewe / laravel-rajaongkir example snippets


$app->withFacades();

class_alias('Pewe\RajaOngkir\Facades\Province', 'Province');
class_alias('Pewe\RajaOngkir\Facades\City', 'City');
class_alias('Pewe\RajaOngkir\Facades\Cost', 'Cost');

$app->register(Pewe\RajaOngkir\Providers\RajaOngkirServiceProvider::class);

$app->configure('rajaongkir');


namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
/*...*/


use City; //if using class_alias
//use Pewe\RajaOngkir\Facades\City; //if not using class_alias

class ExampleController extends Controller
{
  /*...*/
  public function getCities(){
    dd(City::all());
  }
}

City::all();

City::find($id);

Province::all();

Province::find($id);

Cost::couriers($destination,$weight,$origin);

Cost::calculate($destination,$courier,$weight,$origin,$service);

  
   if ( ! function_exists('config_path'))
   {
     /**
      * Get the configuration path.
      *
      * @param  string $path
      * @return string
      */
      function config_path($path = '')
      {
         return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
      }
    }
  
boostrap/app.php
vendor/pewe/laravel-rajaongkir/src/config/rajaongkir.php

php artisan vendor:publish --tag=laravel-rajaongkir-config
helpers.php
composer dump-autoload