0

I get the title error enter image description here when I run command: php artisan db:seed. I want to store data in database. migration is already don. but when seeding it shows and error. I have no idea where this problem comes from.

ProductFactory.php

<?php

namespace Database\Factories;

use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;

class ProductFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Product::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name' => $this->faker->word,
            'detail' => $this->faker->paragraphs,
            'price' => $this->faker->numberBetween(100, 1000),
            'stock' => $this->faker->randomDigit(),
            'discount' => $this->faker->numberBetween(2, 30),
        ];
    }
}

DatabaseSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // \App\Models\User::factory(10)->create();
        \App\Models\Product::factory(50)->create();
       
    }
}
Muqadar Ali
  • 57
  • 2
  • 11
  • what's the exact error? it should point you in the right direction. I cant see anything wrong on first sight – Flame Apr 22 '21 at 11:01
  • @Flame i edit the question please check the screen shot – Muqadar Ali Apr 22 '21 at 11:04
  • `dd($var)` the array from the `definition()` function, it appears to contain an array? Or it happens later on in the process where `updated_at`/`created_at` are added into the object. – Flame Apr 22 '21 at 11:08

2 Answers2

1

use

'detail' => $this->faker->paragraph,

instead of

'detail' => $this->faker->paragraphs,
Zakaria Ab
  • 28
  • 4
0

$this->faker->paragraphs() and $this->faker->words accepts two arguments optionally, the number of paragraphs and words, and a boolean for whether or not to return as an array or string

Use this

'detail' => $this->faker->paragraph,

In place of:

'detail' => $this->faker->paragraphs,
Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38