Answers for "php generate random records in the database"

PHP
0

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
Posted by: Guest on September-29-2021

Code answers related to "php generate random records in the database"

Browse Popular Code Answers by Language