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?
You should add latitute
and others as properties. So, try something like this:
$faker->latitude(-90, 90)
Or:
$faker->latitude()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With