geographer
geographer copied to clipboard
Undefined index: long
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?
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)
Okay, but I need the whole city, how can I do this?