/LaravelPostcodes

A service wrapper around postcodes.io

Primary LanguagePHPMIT LicenseMIT

LaravelPostcodes

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A service wrapper around postcodes.io with validation rule and macro

Install

Via Composer

$ composer require juststeveking/laravel-postcodes

Usage

You can use the validation rule:

<?php

$this->validate($request, [
    'postcode' => [
        'required',
        'string',
        new Postcode()
    ]
]);

Or you can use the validation Macro:

$this->validate($request, [
    'postcode' => [
        'required',
        'string',
        Rule::postcode()
    ]
]);

If you want to interact with the service itself

<?php 

class SomeController extends Controller
{
    protected $postcodes;

    public function __construct(PostcodeService $service)
    {
        $this->postcodes = $service;
    }

    public function store(Request $request)
    {
        // validation using example above
        $location = $this->postcodes->getPostcode($request->postcode);
    }
}

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.