truncate(); $this->call([ TagSeeder::class ]); News::truncate(); $tags = Tag::query()->get(); News::factory(119)->create() ->each(function ($model) use ($tags) { $offset = rand(0, 5); $length = rand(1, 4); $model->tags() ->saveMany($tags->slice($offset, $length)); $model->save(); }); } }