Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gocanto/places-validation

Laravel package to allow users addresses validation
https://github.com/gocanto/places-validation

google laravel php places validation

Last synced: about 4 hours ago
JSON representation

Laravel package to allow users addresses validation

Awesome Lists containing this project

README

        

# Places Validation

Total Downloads
Build Status
Latest Stable Version

Places validation is a ***laravel*** library that will help you out to handle your user addresses. Its aim is making sure the addresses submitted by users are valid through 3rd party services, as google.

# Installation

Begin by installing the package through Composer. Run the following command in your terminal:

```bash
composer require gocanto/places-validation
```

Once composer is done, add the package service provider in the providers array in `config/app.php`:

```php
Gocanto\AddressValidation\ValidatorServiceProvider::class
```

# Client Side

```Vuejs``` component which implements the google autocomplete library:

* Repository: https://github.com/gocanto/google-autocomplete
* Demo: https://gocanto.github.io/google-autocomplete/

# Settings

You will be able to set the validator driver into ```config/addressval.php``` file. At the moment, the package just has the ability to work with google, but others services are planned ahead.

The array driver looks like this:
```php
'driver' => [

//api key if required
'key' => '',

//driver object
'name' => 'GeoogleGeocode',

//api url
'api' => 'http://maps.google.com/maps/api/geocode/json'
],
```

if you do not set the driver within this file, the default one will be used.

# Validate user address using the Laravel validator object

Now you will be able to use this package to validate the user address information within your validations rules. This is how it would look like:

```php
$rules = [
'address' => 'valid_place'
];

$data = [
'address' => 'Guacara, Carabobo, Venezuela'
];

$v = \Validator::make($data, $rules);
```

You will be able to see the implementation on ManagerTest

# Use out of the Laravel object

To implement the validation within your project, you have to include the Checker object as so:
```php
use Gocanto\AddressValidation\Lib\Checker;
```

then, you can let laravel to handle the dependency injection for you, as so:
```php
public function index(Checker $places)
{

if ( ! $v = $places->validate('Guacara, Carabobo, Venezuela')) {
//the place is not valid.
}

//retrieve the place information.
dd($v->retrieve(), $v->location());
}
```

***Output Illustration***

![example](https://github.com/gocanto/places-validation/blob/dev/src/Examples/google-output.png)

# Inspiration

The inspiration came from a needed of using the validation within a form request object. I used [Prosper Otemuyiwa](https://github.com/unicodeveloper/laravel-password) package to have a scope of what I had to do.

# Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

# License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

# How can I thank you?
Why not star the github repo? Why not share the link for this repository on Twitter? Spread the word!

Don't forget to [follow me on twitter](https://twitter.com/gocanto)!

Thanks!

Gustavo Ocanto.
[email protected]