Installation
Get started with mdg-utils for Laravel
mdgascar/mdg-utils-laravel adds validation rules, Eloquent casts and Blade directives on top of the PHP package. Laravel 12 and 13, PHP 8.3+.
Installing in a Laravel app
Section titled “Installing in a Laravel app”-
Require the package
Section titled “Require the package”Terminal composer require mdgascar/mdg-utils-laravelLaravel discovers the service provider on its own. The package brings in
mdgascar/mdg-utils, so every class from Using Composer works too. -
Validate input
Section titled “Validate input”Use the string rules, or the rule objects if you prefer classes.
app/Http/Controllers/OrderController.php use Mdgascar\MdgUtils\Laravel\Rules\AriaryAmount;$request->validate(['phone' => ['required', 'mg_phone'],'total' => ['required', new AriaryAmount()], // or 'mg_ariary']);mg_phonepasses for034 12 345 67or+261 34 12 345 67and fails for031 12 345 67.mg_ariarypasses forAr 1 500,1 500,50or1500from JSON. Messages come in English and French. -
Cast model attributes
Section titled “Cast model attributes”app/Models/Order.php use Mdgascar\MdgUtils\Laravel\Casts\AsAriary;use Mdgascar\MdgUtils\Laravel\Casts\AsPhoneNumber;protected function casts(): array{return ['phone' => AsPhoneNumber::class, // stored as +261341234567'total' => AsAriary::class, // stored as a number];}$order = Order::create(['phone' => '034 12 345 67', 'total' => 'Ar 1 500']);$order->phone->operator; // Operator::Yas$order->total->amount; // 1500 -
Print values in Blade
Section titled “Print values in Blade”resources/views/orders/show.blade.php @ariary($order->total) {{-- Ar 1 500 --}}@mgPhone($order->phone) {{-- 034 12 345 67 --}}@mgWords(2026) {{-- enina amby roapolo sy roa arivo --}}@mgDate($order->created_at) {{-- 27 Novambra 2026 --}}Each directive escapes its output and prints nothing for
null.
Configuration
Section titled “Configuration”Only Ariary amounts have options. Publish config/mdg-utils.php with
php artisan vendor:publish --tag=mdg-utils, or set the environment variables.
| Key | Env | Values | Default |
|---|---|---|---|
ariary.grouping |
MDG_UTILS_ARIARY_GROUPING |
space, dot, comma |
space |
ariary.symbol_position |
MDG_UTILS_ARIARY_SYMBOL_POSITION |
before, after |
before |
ariary.decimal |
MDG_UTILS_ARIARY_DECIMAL |
comma, dot |
comma |