Torann / laravel-geoip

Determine the geographical location of website visitors based on their IP addresses.
http://lyften.com/projects/laravel-geoip
BSD 2-Clause "Simplified" License
2.09k stars 372 forks source link

Using the contract to inject the concrete class #72

Closed arcanedev-maroc closed 7 years ago

arcanedev-maroc commented 7 years ago

ping @Torann

DONE:

Suggestions:

Usage:

<?php

namespace App\Http\Controllers;

use Torann\GeoIP\Contracts\GeoIPInterface;

class RandomController extends Controller
{
    /**
     * GeoIp instance.
     * 
     * @var \Torann\GeoIP\Contracts\GeoIPInterface
     */
    protected $geoip;

    /**
     * Constructor
     * 
     * @param  \Torann\GeoIP\Contracts\GeoIPInterface  $geoip
     */
    public function __construct(GeoIPInterface $geoip)
    {
        $this->geoip = $geoip;
    }

    /**
     * Search ip and do other stuff.
     * 
     * @param  string  $ip
     * 
     * @return mixed
     */
    public function search($ip)
    {
        $location = $this->geoip->getLocation($ip);

        // other stuff
    }
}