Laravel - Database - Persisting Models

The create method instantiates model instances and persists them to the database using Eloquent's save method:

    
    use App\Models\User;
    
    public function test_models_can_be_persisted()
    {
        // Create a single App\Models\User instance...
        $user = User::factory()->create();
    
        // Create three App\Models\User instances...
        $users = User::factory()->count(3)->create();
    
        // Use model in tests...
    }
	

You may override the factory's default model attributes by passing an array of attributes to the create method:

    
    $user = User::factory()->create([
        'name' => 'Abigail',
    ]);