GithubHelp home page GithubHelp logo

kojotete / laravel-plant Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simshaun/laravel-plant

0.0 1.0 0.0 150 KB

Plant is a Laravel bundle that offers an easy way to seed your project with data using "seeds" (data fixtures). DISCLAIMER: This package is no longer maintained since Laravel came out with its own seeding mechanism.

PHP 100.00%

laravel-plant's Introduction

Plant

Plant is a bundle for Laravel that offers an easy way to seed your project and/or tests with data using "seeds". Works well in combination with the excellent Faker library.


Getting started

  1. Install by running php artisan bundle:install plant

  2. Enable the plant bundle in application/bundles.php

  3. Create a seeds folder in your application directory.

  4. Create seed files. For example:

    <?php // file: /application/seeds/users.php
    
    class Seed_Users extends \S2\Seed {
    
        public function grow()
        {
            $user = new User;
            $user->username = 'johndoe';
            $user->password = '12345678';
            $user->save();
    
            $user = new User;
            $user->username = 'janedoe';
            $user->password = '12345678';
            $user->save();
        }
    
        // This is optional. It lets you specify the order each seed is grown.
        // Seeds with a lower number are grown first.
        public function order()
        {
            return 100;
        }
    
    }
    

Controlling the order that seeds are grown

Each seed class may contain an order() method that returns a sort order integer. Seeds with a lower sort order are grown first.


Growing Seeds

All at once

run php artisan plant::seed all

Excluding seeds

You can exclude specific seeds from being grown by using the --not option. Separate multiple exclusions with a comma.

e.g. php artisan plant::seed all --not=users,posts

Multiple seeds (e.g. users,posts)

run php artisan plant::seed users,posts

Regardless of the order you list the seeds in the CLI command, Plant will always grow them according to each seed's sort order.

Individual seeds (e.g. users)

run php artisan plant::seed users

If multiple seeds with the same filename exist, they will all be grown. This could happen when seeds are stored in bundles. e.g. application/seeds/users.php and bundles/plant/seeds/users.php

Sort orders are still used.


References

If a seed needs to reference an object that was created in another seed, use the references feature as shown below.

<?php // file: /application/seeds/users.php

class Seed_Users extends \S2\Seed {

    public function grow()
    {
        $user = new User;
        $user->username = 'johndoe';
        $user->password = '12345678';
        $user->save();

        $this->addReference('user-a', $user);
    }

    public function order()
    {
        return 100;
    }

}
<?php // file: /application/seeds/posts.php

class Seed_Posts extends \S2\Seed {

    public function grow()
    {
        $post = new Post;
        $post->user_id = $this->getReference('user-a')->id;
        $post->title = 'Lorem Ipsum Foo Foo';
        $post->save();
    }

    // This seed must be grown after the users seed
    // so that it can access the "user-a" reference.
    public function order()
    {
        return 200;
    }

}

Issues

If you find any bugs or have suggestions, please add them to the Issue Tracker.

laravel-plant's People

Contributors

simshaun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.