layout: default title: Configuration nav_order: 3 —

Configuration

Table of contents

  1. Full Configuration
  2. Data Version
  3. Storage Path
  4. Table Prefix
  5. Custom Models
    1. Example: Adding a Column
    2. Update Configuration
  6. HTTP Settings
    1. Increase Timeouts
    2. Custom User-Agent

After publishing the config file, customize the package behavior in config/postcode.php.

Full Configuration

<?php

return [
    // Data version identifier
    'data_version' => '1.0.0',

    // Last update date
    'data_updated_at' => '2026-06-22',

    // CSV file storage path
    'storage_path' => storage_path('app/postcode'),

    // Database table prefix (null = no prefix)
    'table_prefix' => null,

    // Custom Eloquent models
    'models' => [
        'state'    => Ajangsupardi\PostcodeMy\Models\State::class,
        'postcode' => Ajangsupardi\PostcodeMy\Models\Postcode::class,
        'location' => Ajangsupardi\PostcodeMy\Models\Location::class,
    ],

    // HTTP client settings
    'http' => [
        'timeout' => 60,
        'connect_timeout' => 10,
        'retry' => 3,
        'retry_delay' => 1000,
        'user_agent' => 'Mozilla/5.0 (compatible; LaravelPostcodeMy/1.0)',
    ],
];

Data Version

Track the version and last update date of your bundled data:

'data_version' => '1.0.0',
'data_updated_at' => '2026-06-22',

Bump these values after running postcode:download and postcode:seed to keep track of data freshness.


Storage Path

Customize where the downloaded CSV file is stored:

'storage_path' => storage_path('app/postcode'),

Use an absolute path or storage_path() helper for reliability.


Table Prefix

Use a prefix to avoid table name conflicts with other packages:

'table_prefix' => 'my_',

This creates tables: my_states, my_postcodes, my_locations.

If you change the prefix after seeding, you’ll need to re-run migrations and seeders.


Custom Models

Extend the default models to add columns, relationships, or custom logic.

Example: Adding a Column

<?php

namespace App\Models;

use Ajangsupardi\PostcodeMy\Models\State as BaseState;

class State extends BaseState
{
    protected $fillable = ['name', 'code', 'population'];

    public function stats()
    {
        return $this->hasOne(StateStat::class);
    }
}

Update Configuration

'models' => [
    'state' => App\Models\State::class,
],

If you add new columns, create a migration to add them to the database table.


HTTP Settings

Configure the HTTP client for downloading data from Pos Malaysia:

Setting Type Default Description
timeout int 60 Request timeout in seconds
connect_timeout int 10 Connection timeout in seconds
retry int 3 Number of retry attempts
retry_delay int 1000 Delay between retries in milliseconds
user_agent string Mozilla/5.0... Custom User-Agent string

Increase Timeouts

If you experience connection issues:

'http' => [
    'timeout' => 120,
    'connect_timeout' => 30,
],

Custom User-Agent

Some servers block generic user agents:

'http' => [
    'user_agent' => 'YourApp/1.0 (your@email.com)',
],