Code Monkey home page Code Monkey logo

countries-laravel's Introduction

Countries for Laravel

World Map

Latest Stable Version License Code Quality Build

Coverage PHP Downloads StyleCI

What does it gives you?

This package has all sorts of information about countries:

info items
taxes 32
geometry maps 248
topology maps 248
currencies 256
countries 266
timezones 423
borders 649
flags 1,570
states 4,526
cities 7,376
timezones times 81,153

Validation

The validation is extending Laravel's validation, so you can use it like any other validation rules, like

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $this->validate($request, [
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
        'country' => 'country' //Checks if valid name.common
    ]);

    // The blog post is valid, store in database...
}

Which validation rules there is and what there name should be, can all be configured in the configuration file.

'validation' => [
    'rules' => [
	    'countryCommon' => 'name.common'
	]
]

By changing the configuration like this, we can now access the property name.common, by the validation rule countryCommon

You have to define all the validations rules in settings, only a few is defined by default, the default is

'rules' 	=> [
    'country' 			=> 'name.common',
    'cca2',
    'cca3',
    'ccn3',
    'cioc',
    'currencies'			=> 'ISO4217',
    'language',
    'language_short'	=> 'ISO639_3',
]

Documentation

This package is a Laravel bridge, please refer to the main package repository for more information and docs.

Requirements

  • PHP 7.0+
  • Laravel 5.5+

Installing

Use Composer to install it:

composer require pragmarx/countries-laravel

Publishing assets

You can publish configuration by doing:

php artisan vendor:publish --provider=PragmaRX\\CountriesLaravel\\Package\\ServiceProvider

Usage

After installing you'll have access to the Countries Façade, and the package is based on Laravel Collections, so you basically have access to all methods in Collections, like

$france = Countries::where('name.common', 'France');

Flag routes

You can refer directly to an SVG flag by linking

/pragmarx/countries/flag/download/<cca3-code>.svg
/pragmarx/countries/flag/file/<cca3-code>.svg

Examples:

https://laravel.com/pragmarx/countries/flag/download/usa.svg
https://laravel.com/pragmarx/countries/flag/file/usa.svg

http://pragmarx.test/pragmarx/countries/flag/file/usa.svg

Author

Antonio Carlos Ribeiro

License

Countries is licensed under the MIT License - see the LICENSE file for details

Contributing

Pull requests and issues are more than welcome.

countries-laravel's People

Contributors

andershagbard avatar antonioribeiro avatar lionslair avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.