lucasvdh / laravel-iban
A Laravel plugin for IBAN validation
Installs: 6 959
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: >=5.6.0
- laravel/framework: ^5.0
This package is auto-updated.
Last update: 2024-11-07 00:38:06 UTC
README
IBAN validation made easy.
Getting started
Include the package in your application
$ composer require lucasvdh/laravel-iban:5.*
Or add a requirement to your project's composer.json
"require": { "lucasvdh/laravel-iban": "5.*" },
TODO: register package at the packagist
Register the service
Add the following to your config/app.php
<?php return [ ... 'providers' => [ ... IBAN\ServiceProvider::class, ], ... // Optionally you can register the Facade alias 'aliases' => [ ... 'IBAN' => IBAN\Facades\IBAN::class, ], ];
Example usages
IBAN validation can be used in the following ways:
Via the facade
function validateIBAN($iban) { echo $iban; if (\IBAN::validate($iban)) { echo 'is a valid IBAN'; } else { echo 'is NOT valid IBAN'; } echo "\r\n"; } validateIBAN('NL39 RABO 0300 0652 64'); validateIBAN('123456789');
This results in
NL39 RABO 0300 0652 64 is a valid IBAN
123456789 is NOT a valid IBAN
Via dependency injection
<?php namespace App\Http\Controllers; use IBAN\Services\IBANService; class IBANController extends Controller { public function validate(IBANService $IBANService, $iban) { if ($IBANService->validate($iban)) { return response()->json([ 'message' => $iban . 'is a valid IBAN' ]); } else { return response()->json([ 'message' => $iban . 'is NOT a valid IBAN' ]); } } }
Via validation rules
$validator = Validator::make( ['required_iban_field' => 'required|iban'], ['optional_iban_field' => 'sometimes|iban'], );