It's quite random to me if I need to have a use
statement to access a class. In the following code, which runs without issues, the Faker
library doesn't need use Faker
or something like that, yet the Seeder
does need an use
.
I assume Faker
is accessed using the Composer autoloader, yet in composer.json I don't see the vendor
directory being used for either the psr-4 autoload or the classmap autoload, so how it finds this is beyond me.
<?php
use Illuminate\Database\Seeder;
class MoreProductsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i = 0; $i<1000; $i++)
{
$faker = Faker\Factory::create();
\App\Product::create([
'name' => $faker->name,
'photo' => 'https://picsum.photos/200/300',
'price' => rand(1,20000),
'category_id' => rand(1,3)
]);
}
}
}