Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 217 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Laravel 4 db seed specific seeder file

#1
I have an existing user table with information seeded via `db:seed` from UserSeeder.php. Now, I am adding new product table and want to seed information into product table. How can I prevent Laravel from seeding the UserSeeder into the database, but only the new ProductSeeder being seeded?

Thanks.
Reply

#2
Here's a working example with the class full namespace:

Should use double backslashes `\\`.

Class name is `DefaultBannersSeeder`.

php artisan db:seed --class=App\\Containers\\Banners\\Data\\Seeders\\DefaultBannersSeeder
Reply

#3
You can call individual seed classes by their class name.
From the [docs][1].

> By default, the db:seed command runs the DatabaseSeeder class, which
> may be used to call other seed classes. However, you may use the
> --class option to specify a specific seeder class to run individually:

php artisan db:seed --class=ProductTableSeeder
In the example above, the `ProductTableSeeder` class should exist in `database/seeds`.


[1]:

[To see links please register here]

Reply

#4
You can also edit your `database/seeders/DatabaseSeeder.php` file's `$this->call()` instruction:

<?php
namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
UserTableSeeder::class,
PermissionsSeeder::class
]);
}
}

Reply

#5
I put my seeders in folders in accordance with their meaning.
I have `LookupSeeders`, `DemoSeeders`, `TestSeeders`...

for example I need to run this seeder - `project\database\seeds\LookupSeeders\CountrySeeder.php`

This is how you can do it... say from `project\tests\autoload.php` file

echo shell_exec('php artisan db:seed --class=LookupSeeders\\\\CountrySeeder');
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through