mardi 8 novembre 2016

Array to string conversion when trying to seed database with faker in laravel 5.3

specifically this error only occurs with this:

$faker->randomElements($array = array('long','short','shoulder length')),

Output from php artisan db:seed

    [Illuminate\Database\QueryException]                                                                  
  Array to string conversion (SQL: insert into `profiles` (`agency_id`, `name`, `bio`, `age`, `hair_ty  
  pe`, `updated_at`, `created_at`) values (1, Cathy, Placeat voluptas tenetur corrupti et., 44, short,  
   2016-11-08 15:09:00, 2016-11-08 15:09:00)) 

     [ErrorException]            
  Array to string conversion 

Is there any attributes that I need to add to make this work, the sql clearly shows the randomly generated value in the query exception, nothing in the laravel logs.

Associated model:

namespace App;

use App\Profile;

use Illuminate\Database\Seeder;

class ProfileTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $faker = \Faker\Factory::create();

        foreach(range(1,50) as $index)
        {
            Profile::create([
                'agency_id'         =>  '1',
                'name'              =>  $faker->firstName($gender = 'female'),
                'bio'               =>  $faker->sentence(4),
                'age'               =>  $faker->numberBetween($min=19, $max=46),
                'hair_type'         =>  $faker->randomElements($array = array('long','short','shoulder length'))
       ]);
    }
  }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire