Countries for Laravel

Overview

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/.svg
/pragmarx/countries/flag/file/.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

These routes can be turned off in the configuration file:

'routes' => [
    'enabled' => false,
]

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.

Comments
  • Can't install on Laravel 7

    Can't install on Laravel 7

    There is an error when installing on Laravel 7:

    Problem 1
        - Conclusion: remove nesbot/carbon 2.31.0
        - Conclusion: don't install nesbot/carbon 2.31.0
        - pragmarx/ia-collection v5.5.33 requires nesbot/carbon ~1.20 ->
    
    opened by vezlius 8
  • Latest Updates broken

    Latest Updates broken

    Just did a composer update and the latest update appears to have broken things.

    Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover

    In Container.php line 767:

    Class PragmaRX\Countries\Package\Services\Cache does not exist

    It's in the PragmaRX\Countries package. I cleared my composer cache reinstalled all and still occurs.

    opened by lionslair 6
  • Laravel v6 Support

    Laravel v6 Support

    Your package is making calls to string helper functions such as camel_case which have been removed in Laravel 6. It would be nice to get an update on this package so I don't have to pull in the string helpers package just to make stuff work again whenever this package is called in the application.

    opened by rawilk 2
  • Unable to publish configuration file

    Unable to publish configuration file

    According to documentation, then it should be possible to publish the packages config file using

    php artisan vendor:publish --provider=PragmaRX\Countries\ServiceProvider

    But no configuration file is generated.

    Clearing the cache with php artisan config:clear does not seem to fix the issue nor does php artisan cache:clear

    I am currently testing on Laravel 5.5 (and I am using this repository in composer: "pragmarx/countries-laravel": "^0.5.2")

    opened by bilfeldt 2
  • Allow turning off route registration in the ServiceProvider

    Allow turning off route registration in the ServiceProvider

    I didn't want to have the routes automatically registered in my application, so I added a config flag in order to turn them off (still enabled by default, so no breaking changes).

    Tested locally with the new config both on and off as well as with the previous config and the default of being on is present.

    opened by RyanTheAllmighty 1
  • Collection whereIn not working

    Collection whereIn not working

    $countries= \Countries::whereIn('cca2', $array)->sortBy('name')->pluck('name.common', 'cca2')->toArray(); Is this not supported anymore?

    I was using pragmarx/countries:0.1.1 (way too old version) which get me wrong name for czech republic. So now trying to update to latest version we needed to pull in this package but sadly whereIn was not working for this package. Was i doing anything wrong? or there is different methods now?

    opened by AnujShr 0
  • *Feature* Localization  The Countries

    *Feature* Localization The Countries

    Hello, Thank You, Mr @antonioribeiro For This Cool Package 📦

    It Would Be Cool If The Is A Localization Feature So Any One Could Use Its Own Languages For Example I May Want To The Countries Name To Be In Arabic Brazil Become برازيل In Arabic

    I Believe This Would Be Helpful Of Course We Are Ready To Contribute

    opened by zymawy 0
  • Usage of flags directly

    Usage of flags directly

    Hi @antonioribeiro.

    I have a (probably dumb) question.

    How do you use the flags directly?

    I've hydrated it and they're coming on the Countries...

    The thing is that they just spit out some html and I've used it with the:

    {!! $country->flag-icon !!}     // prints <span class="flag-icon flag-icon-abw"></span>
    

    or

    {!! $country->flag-icon-squared !!}      // prints <span class="flag-icon flag-icon-abw flag-icon-squared"></span>
    

    or even

    {!! $country->world-flags-sprite !!}     // prints <span class="flag abw"></span>
    

    It seems that you are using the convention

    <span class="flag-icon flag-icon-{{ strtolower($country->ccn3) }}"></span> // this works
    

    and every package ob github that matches this "style" is using another convention

    <span class="flag-icon flag-icon-{{ strtolower($country->cca2) }}"></span>    // this is what I found online on https://github.com/lipis/flag-icon-css
    
    opened by rjdmacedo 0
  • Update dependencies to make it compatible with Laravel9

    Update dependencies to make it compatible with Laravel9

    Description

    Update psr/simple-cache, pragmarx/countries and pragmarx/coollection dependencies. Also remove composer.lock and update travis config file.

    Motivation and context

    Laravel 9.x requires symfony/var-dumper ^6.0 and voku/portable-ascii ^2.0. This is part of some updates on multiple pragmarx packages which aren't compatible with Laravel9 yet, this helps fixing that.

    See

    • https://github.com/antonioribeiro/countries/pull/193
    • https://github.com/antonioribeiro/coollection/pull/14
    • https://github.com/antonioribeiro/ia-str/pull/5
    • https://github.com/antonioribeiro/ia-collection/pull/11
    • https://github.com/antonioribeiro/ia-arr/pull/4
    opened by asbiin 5
  • Country Flags are not shown on windows OS

    Country Flags are not shown on windows OS

    When i open website from Linux OS flags are shown as they should 1 but when i open it using the windows 10 OS, i see letters 2

    Anyone have such issue ? How to fix it ?

    opened by eXCom 1
  • Fix #27 validation rules are not deferred

    Fix #27 validation rules are not deferred

    @antonioribeiro I think this will fix the problems described in https://github.com/antonioribeiro/countries-laravel/issues/27 and https://github.com/antonioribeiro/countries-laravel/issues/14

    opened by ametad 1
  • Validation rules won't work until manual loading the provider once

    Validation rules won't work until manual loading the provider once

    Hi @antonioribeiro ,

    Thank you for your work on this package. I have a question on the validation rules that I don't seem to get working. It looks like the validation rules are not yet loaded before you load app('pragmarx.countries'); explicitly. After that the validation does work correctly.

    Version "pragmarx/countries-laravel" === '0.6.3'

    Example steps to reproduce the error

    class PostController extends Controller
    
        public function store(Request $request)
        {
            // Without this the 'cca2' validation rule gives error. Please toggle on/off.
            $foo = app('pragmarx.countries');
    
            $validated = $this->validate($request, [
               'country_code' => 'nullable|string|size:2|cca2',
            ];
    
            dd($validated);
        }
    

    The error I get when the rule is not loaded:

    Method Illuminate\Validation\Validator::validateCca2 does not exist.

    Perhaps this has something to do with the defered state in \PragmaRX\CountriesLaravel\Package\ServiceProvider ?

    opened by ametad 1
Owner
Antonio Carlos Ribeiro
Antonio Carlos Ribeiro
A simple Laravel Package to sort Countries, States and Cities

Laravel Location ▲ Introduction ?? This Package offers a simple way to get Countries, Cities and States that you may need for your Application, most e

Michael Okoh 197 Jan 1, 2023
Laravel countries and currencies

Countries What does it gives you? This package has all sorts of information about countries: info items taxes 32 geometry maps 248 topology maps 248 c

Antonio Carlos Ribeiro 1.7k Dec 29, 2022
Countries for Laravel

Countries for Laravel What does it gives you? This package has all sorts of information about countries: info items taxes 32 geometry maps 248 topolog

Antonio Carlos Ribeiro 140 Jan 5, 2023
Library for getting countries info from restcountries.com

librestcountries Library for getting countries info from restcountries.com Description Library for getting countries info from restcountries.com Getti

null 4 Sep 18, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022
Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster.

Laravel Kickstart What is Laravel Kickstart? Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster. It com

Sam Rapaport 46 Oct 1, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 13 May 16, 2022
Laravel Sanctum support for Laravel Lighthouse

Lighthouse Sanctum Add Laravel Sanctum support to Lighthouse Requirements Installation Usage Login Logout Register Email Verification Forgot Password

Daniël de Wit 43 Dec 21, 2022
Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

Pham Thao 9 Nov 10, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
Laravel Jetstream is a beautifully designed application scaffolding for Laravel.

Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream provides the perfect starting point for your next Laravel application and includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management.

The Laravel Framework 3.5k Jan 8, 2023
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

Luca Patera 68 Dec 12, 2022
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Hussein Feras 52 Jul 17, 2022
A Laravel extension for using a laravel application on a multi domain setting

Laravel Multi Domain An extension for using Laravel in a multi domain setting Description This package allows a single Laravel installation to work wi

null 658 Jan 6, 2023
Example of using abrouter/abrouter-laravel-bridge in Laravel

ABRouter Laravel Example It's a example of using (ABRouter Laravel Client)[https://github.com/abrouter/abrouter-laravel-bridge] Set up locally First o

ABRouter 1 Oct 14, 2021