Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate latitude, longitude info using Faker from Laravel seeder?

Tags:

php

laravel

faker

I am trying to use Faker in a Laravel seeder.

Here is how my seeder class look like

<?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class LatitudeLongitudeTestTableSeeder extends Seeder
{

    public function run()
    {
        $faker = new Faker;

        $myTable = 'LatitudeLongitudeTest';

        foreach (range(1,10) as $index) {
            DB::table($myTable)->insert([
                'Latitude' => $faker->Address->latitude,
                'Longitude' => $faker->Address->longitude,
                'name' => $faker->Address->street_name,
            ]);
        }

    }
}

but this is giving me the following error

[ErrorException] Undefined property: Faker\Factory::$Address

I also tried to access the longitude property like this $faker->longitude but that still did not work.

How can I access the longitude property in faker to generate data?

like image 486
Jaylen Avatar asked Oct 24 '16 18:10

Jaylen


1 Answers

You should add latitute and others as properties. So, try something like this:

$faker->latitude(-90, 90)

Or:

$faker->latitude()
like image 106
Alexey Mezenin Avatar answered Nov 16 '22 05:11

Alexey Mezenin