public function execute($persistLastModel = true)
    {
        $this->addLastModel();

        $insertedPKs = [];
        $createdModels = [];

        foreach ($this->quantities as $modelClass => $quantity) {
            $this->modelPopulators[$modelClass]->setGuessedColumnFormatters(false);

            $persist = $modelClass === $this->lastModelClass ? $persistLastModel : true;

            if ($quantity > 1) {
                $createdModels[$modelClass] = (new $modelClass)->newCollection();
            }

            for ($i = 0; $i < $quantity; $i++) {
                $createdModel = $this->modelPopulators[$modelClass]->run($insertedPKs, $persist);

                $insertedPKs[$modelClass][] = $createdModel->getKey();

                if ($quantity === 1) {
                    $createdModels[$modelClass] = $createdModel;
                } else {
                    $createdModels[$modelClass]->add($createdModel);
                }
            }
        }

        // We'll unset the previously added models so that if, for example, the developer calls
        // $populator->create(App\Foo::class), and then $populator->create(App\Bar::class),
        // Foo won't be created twice.
        $this->forgetAddedModels();

        $this->closeDoctrineConnections();

        return $createdModels;
    }
public function execute($persistLastModel = true)
    {
        $this->addLastModel();

        $insertedPKs = [];
        $createdModels = [];

        foreach ($this->quantities as $modelClass => $quantity) {
            $this->modelPopulators[$modelClass]->setGuessedColumnFormatters(false);

            $persist = $modelClass === $this->lastModelClass ? $persistLastModel : true;

            if ($quantity > 1) {
                $createdModels[$modelClass] = (new $modelClass)->newCollection();
            }

            for ($i = 0; $i < $quantity; $i++) {
                $createdModel = $this->modelPopulators[$modelClass]->run($insertedPKs, $persist);

                $insertedPKs[$modelClass][] = $createdModel->getKey();

                if ($quantity === 1) {
                    $createdModels[$modelClass] = $createdModel;
                } else {
                    $createdModels[$modelClass]->add($createdModel);
                }
            }
        }

        // We'll unset the previously added models so that if, for example, the developer calls
        // $populator->create(App\Foo::class), and then $populator->create(App\Bar::class),
        // Foo won't be created twice.
        $this->forgetAddedModels();

        $this->closeDoctrineConnections();

        return $createdModels;
    }
public function execute ( $ persistLastModel = true ) { $ this -> addLastModel ( ) ; $ insertedPKs = [ ] ; $ createdModels = [ ] ; foreach ( $ this -> quantities as $ modelClass => $ quantity ) { $ this -> modelPopulators [ $ modelClass ] -> setGuessedColumnFormatters ( false ) ; $ persist = $ modelClass === $ this -> lastModelClass ? $ persistLastModel : true ; if ( $ quantity > 1 ) { $ createdModels [ $ modelClass ] = ( new $ modelClass ) -> newCollection ( ) ; } for ( $ i = 0 ; $ i < $ quantity ; $ i ++ ) { $ createdModel = $ this -> modelPopulators [ $ modelClass ] -> run ( $ insertedPKs , $ persist ) ; $ insertedPKs [ $ modelClass ] [ ] = $ createdModel -> getKey ( ) ; if ( $ quantity === 1 ) { $ createdModels [ $ modelClass ] = $ createdModel ; } else { $ createdModels [ $ modelClass ] -> add ( $ createdModel ) ; } } } // We'll unset the previously added models so that if, for example, the developer calls // $populator->create(App\Foo::class), and then $populator->create(App\Bar::class), // Foo won't be created twice. $ this -> forgetAddedModels ( ) ; $ this -> closeDoctrineConnections ( ) ; return $ createdModels ; }
Create the added models.

@param  bool $persistLastModel Whether to persist the last added model in the database.
@return array The inserted models or collections indexed by class name.
Create the added models .