Packaging tables in Laravel 4

I know how to set up package migrations to Laravel 4 (using --bench = "vendor / package" / - package = "vendor / package").

But I can't figure out how to set up seeds for these migrations?

- To clarify - I know how to use the planter, I need to know how to set up the starter file for an individual package? You can provide a package of individual migrations ...

+3


source to share


3 answers


You can use the Seeder class like in the application folder.

Database visit in Laravel 4

For example:

<?php

use Illuminate\Database\Seeder;
use Page;

class MySeeder extends Seeder {

    public function run()
    {
        Page::create(array('title' => 'Foo-Bar !'));
    }

}

      



and put "-class" arg in:

$ php artisan db:seed --class="MySeeder"

      

Make sure your class is loaded by composer :)

+6


source


Laravel Database Seeder will automatically recognize any class name passed to it if Composer successfully loaded all of your classes. Do the following:

  • Create a folder seeds

    in{vendor}/{package}/src

  • Create a planter class, prefix it with your package name to avoid conflicts, for example {Package}Seeder.php

    will work.
  • Add a new folder seeds

    to your composer.json

    autoload classmap package .
  • In a terminal, run composer update

    from the root folder of your package.
  • In terminal, run php artisan db:seed --class={Package}Seeder

    (replace the class name with the new class name.)


What is it. You can now launch seeds for your pack.

M

+3


source


To make sure your seed files don't conflict, you can add the namespace to the sample file

namespace YourPackage\Name;

class DatabaseSeeder extends Seeder {

      

And then run the artisan command with FQCN

$ php artisan db:seed --class="YourPackage\Name\DatabaseSeeder"

      

or if you don't use quotes

$ php artisan db:seed --class=YourPackage\\Name\\DatabaseSeeder

      

+2


source







All Articles