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 ...
source to share
You can use the Seeder class like in the application folder.
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 :)
source to share
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 yourcomposer.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
source to share
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
source to share