php artisan tinkerProduct::factory()->count(500)->create()

laravel factory

<?php namespace Database\Factories; use App\Models\Comment; use App\Models\Post; use Illuminate\Database\Eloquent\Factories\Factory; class CommentFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = Comment::class; /** * Define the model's default state. * * @return array */ public function definition() { $post_ids = Post::pluck('id')->toArray(); return [ 'comment' => $this->faker->text(), 'post_id' => $post_ids[array_rand($post_ids)] ]; } }

How to make a custom factory in Laravel

For Laravel version 7.* and less factory(App\User::class, 3)->make(); Use create method to persist them to the database: factory(App\User::class, 3)->create();

add factory data laravel

Similar Code Examples