php generate random records in the database
model news.php
class new extends Model
{
use HasFactory;
protected $fillable = ['title' , 'new'];
}
NewsFactory.php
public function definition()
{
return [
'title' => $this->faker->text(rand(10,40)),
'new' => $this->faker->text(rand(200,400))
];
}
NewsSeeder.php
public function run()
{
ini_set('memory_limit' , '512M');
// generate 100 news
\App\Models\Noticia::factory(100)->create();
}
In the end, execute the command: php artisan db:seed --class=NewsSeeder