geographer icon indicating copy to clipboard operation
geographer copied to clipboard

Undefined index: long

Open Jlomaka opened this issue 8 years ago • 2 comments

Good afternoon, when I try to get all the cities on request

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use MenaraSolutions\Geographer\Earth;
use MenaraSolutions\Geographer\City;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $city = new City();
        $city = $city->toArray();
        View::share('city', $city);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

and

    <pre>
    <?php var_dump($city); ?>
    </pre>

Have some error: Undefined index: long what am I doing wrong?

Jlomaka avatar Jul 30 '17 14:07 Jlomaka

You can't instantiate a city object like this! :) You have to use build() method and pass a city ID (that you can get from GeoIP/GeoNames for example)

dusterio avatar Jul 30 '17 22:07 dusterio

Okay, but I need the whole city, how can I do this?

Jlomaka avatar Jul 30 '17 23:07 Jlomaka