/laravel-myanmar-tools

A package for Myanmar tools which extend Laravel’s core.

Primary LanguagePHPMIT LicenseMIT

Laravel Myanmar Tools

Run tests

A package for Myanmar tools which extend Laravel’s core.

Table of Contents

Installation

composer require pyaesoneaung/laravel-myanmar-tools

Version Compatibilities

Laravel Myanmar Tools Laravel 9.* Laravel 8.* Laravel 7.* Laravel 6.*
2.x
1.x

Documentation

Read the full documentation at laravel-myanmar-tools.com

Str

isUnicodeFont()

use Illuminate\Support\Str;
Str::isUnicodeFont('မြန်မာပြည်'); // return true

isZawgyiFont()

use Illuminate\Support\Str;
Str::isZawgyiFont('ျမန္မာျပည္'); // return true

detectMyanmarFont()

use Illuminate\Support\Str;
Str::detectMyanmarFont('မြန်မာပြည်'); // return 'unicode'
Str::detectMyanmarFont('ျမန္မာျပည္'); // return 'zawgyi'

zgToUni()

use Illuminate\Support\Str;
Str::zgToUni('ျမန္မာျပည္'); // return 'မြန်မာပြည်'

uniToZg()

use Illuminate\Support\Str;
Str::uniToZg('မြန်မာပြည်'); // return 'ျမန္မာျပည္'

isMyanmarPhoneNumber()

use Illuminate\Support\Str;
Str::isMyanmarPhoneNumber('09250000000'); // return true

isMpt()

use Illuminate\Support\Str;
Str::isMpt('09250000000'); // return true

isOoredoo()

use Illuminate\Support\Str;
Str::isOoredoo('09970000000'); // return true

isTelenor()

use Illuminate\Support\Str;
Str::isTelenor('09790000000'); // return true

isMec()

use Illuminate\Support\Str;
Str::isMec('0930000000'); // return true

isMytel()

use Illuminate\Support\Str;
Str::isMytel('09690000000'); // return true

telecomName()

use Illuminate\Support\Str;
Str::telecomName('09250000000'); // return 'mpt'
Str::telecomName('09970000000'); // return 'ooredoo'
Str::telecomName('09790000000'); // return 'telenor'
Str::telecomName('0930000000');  // return 'mec'
Str::telecomName('09690000000'); // return 'mytel'

normalizeMyanmarPhoneNumber()

use Illuminate\Support\Str;
Str::normalizeMyanmarPhoneNumber('09250000000'); // return '09250000000'
Str::normalizeMyanmarPhoneNumber('(၀၉)၂၅၀၀၀၀၀၀၀'); // return '09250000000'
Str::normalizeMyanmarPhoneNumber('၀၉-၂၅၀၀၀၀၀၀၀'); // return '09250000000'
Str::normalizeMyanmarPhoneNumber('+၉၅၉၂၅၀၀၀၀၀၀၀'); // return '09250000000'
Str::normalizeMyanmarPhoneNumber('09-၂၅ဝရဝရဝရဝ');
// return '09250707070' (ဝလုံး နဲ့ ရကောက် ပါလျှင် 0 နဲ့ 7 လို့ပြောင်းလဲပါသည်)

Request

isUnicodeFont()

// https://domain/path?name=မြန်မာပြည်
$request->isUnicodeFont('name'); // return true

isZawgyiFont()

// https://domain/path?name=ျမန္မာျပည္
$request->isZawgyiFont('name'); // return true

detectMyanmarFont()

// https://domain/path?name=မြန်မာပြည်
$request->detectMyanmarFont('name'); // return 'unicode'

// https://domain/path?name=ျမန္မာျပည္
$request->detectMyanmarFont('name'); // return 'zawgyi'

zgToUni()

// https://domain/path?name=ျမန္မာျပည္
$request->zgToUni('name'); // return 'မြန်မာပြည်'

uniToZg()

// https://domain/path?name=မြန်မာပြည်
$request->uniToZg('name'); // return 'ျမန္မာျပည္'

isMyanmarPhoneNumber()

// https://domain/path?phone=09250000000
$request->isMyanmarPhoneNumber('phone'); // return true

isMpt()

// https://domain/path?phone=09250000000
$request->isMpt('phone'); // return true

isOoredoo()

// https://domain/path?phone=09970000000
$request->isOoredoo('phone'); // return true

isTelenor()

// https://domain/path?phone=09790000000
$request->isTelenor('phone'); // return true

isMec()

// https://domain/path?phone=0930000000
$request->isMec('phone'); // return true

isMytel()

// https://domain/path?phone=09690000000
$request->isMytel('phone'); // return true

telecomName()

// https://domain/path?phone=09250000000
$request->telecomName('phone'); // return 'mpt'

// https://domain/path?phone=09970000000
$request->telecomName('phone'); // return 'ooredoo'

// https://domain/path?phone=09790000000
$request->telecomName('phone'); // return 'telenor'

// https://domain/path?phone=0930000000
$request->telecomName('phone'); // return 'mec'

// https://domain/path?phone=09690000000
$request->telecomName('phone'); // return 'mytel'

normalizeMyanmarPhoneNumber()

// https://domain/path?phone=09250000000
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=(၀၉)၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=၀၉-၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=+၉၅၉၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=09-၂၅ဝရဝရဝရဝ
$request->normalizeMyanmarPhoneNumber('phone');
// return '09250707070' (ဝလုံး နဲ့ ရကောက် ပါလျှင် 0 နဲ့ 7 လို့ပြောင်းလဲပါသည်)

Collection

whereMyanmarPhoneNumber()

$data = ['09250000000', 'abc'];
collect($data)->whereMyanmarPhoneNumber()->toArray();
// ['09250000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => 'abc']
];
collect($data)->whereMyanmarPhoneNumber('phone')->toArray();
/*
    [
        ['phone' => '09250000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => 'abc']],
];
collect($data)->whereMyanmarPhoneNumber('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '09250000000']],
    ]
*/

whereMpt()

$data = ['09250000000', '09970000000'];
collect($data)->whereMpt()->toArray();
// ['09250000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => '09970000000']
];
collect($data)->whereMpt('phone')->toArray();
/*
    [
        ['phone' => '09250000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => '09970000000']],
];
collect($data)->whereMpt('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '09250000000']],
    ]
*/

whereOoredoo()

$data = ['09250000000', '09970000000'];
collect($data)->whereOoredoo()->toArray();
// ['09970000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => '09970000000']
];
collect($data)->whereOoredoo('phone')->toArray();
/*
    [
        ['phone' => '09970000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => '09970000000']],
];
collect($data)->whereOoredoo('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '09970000000']],
    ]
*/

whereTelenor()

$data = ['09250000000', '09790000000'];
collect($data)->whereTelenor()->toArray();
// ['09790000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => '09790000000']
];
collect($data)->whereTelenor('phone')->toArray();
/*
    [
        ['phone' => '09790000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => '09790000000']],
];
collect($data)->whereTelenor('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '09790000000']],
    ]
*/

whereMec()

$data = ['09250000000', '0930000000'];
collect($data)->whereMec()->toArray();
// ['0930000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => '0930000000']
];
collect($data)->whereMec('phone')->toArray();
/*
    [
        ['phone' => '0930000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => '0930000000']],
];
collect($data)->whereMec('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '0930000000']],
    ]
*/

whereMytel()

$data = ['09250000000', '09690000000'];
collect($data)->whereMytel()->toArray();
// ['09690000000']

$data = [
    ['phone' => '09250000000'],
    ['phone' => '09690000000']
];
collect($data)->whereMytel('phone')->toArray();
/*
    [
        ['phone' => '09690000000']
    ]
*/

$data = [
    ['user' => ['phone' => '09250000000']],
    ['user' => ['phone' => '09690000000']],
];
collect($data)->whereMytel('user.phone')->toArray();
/*
    [
        ['user' => ['phone' => '09690000000']],
    ]
*/

uniToZg()

$data = ['မြန်မာပြည်'];
collect($data)->uniToZg()->toArray();
// ['ျမန္မာျပည္']

$data = [
    ['name' => 'မြန်မာပြည်']
];
collect($data)->uniToZg('name')->toArray();
/*
    [
        ['name' => 'ျမန္မာျပည္']
    ]
*/

$data = [
    ['user' => ['name' => 'မြန်မာပြည်']]
];
collect($data)->uniToZg('user.name')->toArray();
/*
    [
        ['user' => ['name' => 'ျမန္မာျပည္']]
    ]
*/

zgToUni()

$data = ['ျမန္မာျပည္'];
collect($data)->zgToUni()->toArray();
// ['မြန်မာပြည်']

$data = [
    ['name' => 'ျမန္မာျပည္']
];
collect($data)->zgToUni('name')->toArray();
/*
    [
        ['name' => 'မြန်မာပြည်']
    ]
*/

$data = [
    ['user' => ['name' => 'ျမန္မာျပည္']]
];
collect($data)->zgToUni('user.name')->toArray();
/*
    [
        ['user' => ['name' => 'မြန်မာပြည်']]
    ]
*/

Validation

myanmarPhoneNumber

$request->validate([
    'phone' => ['required', 'myanmarPhoneNumber'],
]);

mpt

$request->validate([
    'phone' => ['required', 'mpt'],
]);

ooredoo

$request->validate([
    'phone' => ['required', 'ooredoo'],
]);

telenor

$request->validate([
    'phone' => ['required', 'telenor'],
]);

mec

$request->validate([
    'phone' => ['required', 'mec'],
]);

mytel

$request->validate([
    'phone' => ['required', 'mytel'],
]);

Customizing The Error Messages

php artisan vendor:publish --provider="PyaeSoneAung\LaravelMyanmarTools\LaravelMyanmarToolsServiceProvider"

You can edit the error messages at /lang/vendor/laravelMyanmarTools/en/validation.php

return [
    'myanmar_phone_number' => 'The :attribute must be valid myanmar phone number.',
    'mpt' => 'The :attribute must be valid MPT number.',
    'ooredoo' => 'The :attribute must be valid Ooredoo number.',
    'telenor' => 'The :attribute must be valid Telenor number.',
    'mec' => 'The :attribute must be valid MEC number.',
    'mytel' => 'The :attribute must be valid Mytel number.',
];

Version History

  • 2.2.1
    • bug fixed publishing translations
  • 2.2.0
    • added normalizeMyanmarPhoneNumber request macro
  • 2.1.0
    • added normalizeMyanmarPhoneNumber str macro
  • 2.0.0
    • support laravel 9.* | 8.* | 7.* | 6.* 🎉
  • 1.4.1
    • bug fixed collection macros (uniToZg and zgToUni)
  • 1.4.0
    • extended phone number validation
  • 1.3.0
    • improved collection macros
    • changed request macros usage
  • 1.2.0
    • added collection macros
    • improved zawgyi detection
  • 1.1.0
    • added request macros
  • 1.0.0
    • initial release

Credits