Faker laravel unknown formatter image

Am using faker in laravel and in my seeder i have

 public function run()
   {
    $faker = new Faker\Generator();
    //create a user
    $adminuser = App\User::create(
        [
            'name' => 'admin',
            'first_name' => 'firstuser',
            'profile_pic'=>$faker->image('storage/app/public/users',400,300, 'people', false),
        ]
    );

But now am getting an error

Unknown formatter "image"

Where am i going wrong

I just want to add an image to a user generated via faker

phplaravelfaker

Answers

answered 1 week ago ljubadr #1

From the docs on basic usage

public function run()
{
    // instead of using new Faker\Generator()
    $faker = Faker\Factory::create();

    //create a user
    $adminuser = App\User::create(
        [
            'name'        => 'admin',
            'first_name'  => 'firstuser',
            'profile_pic' => $faker->image('storage/app/public/users',400,300, 'people', false),
        ]
    );
}

answered 1 week ago Alihossein shahabi #2

You must use the ‍‍Method Injection

for example :

<?php

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

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @param Faker $faker
     * @return void
     */
    public function run(Faker $faker)
    {
        $adminuser = App\User::create(
            [
               'name' => $faker->name,
                'first_name' => $faker->firstName,
                'profile_pic' => $faker->image(public_path('img'),400,300, 'people', true),
            ]
        );
    }
}

comments powered by Disqus