Reputation: 57
I get the title error 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();
}
}
Upvotes: 0
Views: 703
Reputation: 2834
$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,
Upvotes: 0
Reputation: 28
use
'detail' => $this->faker->paragraph,
instead of
'detail' => $this->faker->paragraphs,
Upvotes: 1