1

I am creating a modular application in Laravel and have used a package called nwidart.I am also using Spatie package for Role and Permission based ACL. This works fine, I have created a seeder class inside my module called API using this command

php artisan module:make-seed PermissionTableSeeder API

This has created a seeder file inside Modules/API/Database/Seeders directory. I have further edited the code in the seeder file as shown below:

<?php

namespace Modules\API\Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;

class PermissionTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $permissions = [
            'role-list',
            'role-create',
            'role-edit',
            'role-delete',
            'blog-list',
            'blog-create',
            'blog-edit',
            'blog-delete'
         ];

        foreach ($permissions as $permission) {
            Permission::create(['name' => $permission]);
        }
    }
}

The problem is am not aware of the specific command to run the seeder class inside the API module.

James Z
  • 12,209
  • 10
  • 24
  • 44
Pweb
  • 155
  • 1
  • 4
  • 18

3 Answers3

1

To run this seed you'll go through 2 steps:

1- if you didn't change the main module seeder then go to Modules\API\Database\Seeders\APIDatabaseSeeder and add the following line to the run function:

$this->call(PermissionTableSeeder::class);

Note that you'll need to use the PermissionTableSeeder class before running the command.

2- run: php artisan module:seed API

check the docs for more info https://nwidart.com/laravel-modules/v6/advanced-tools/artisan-commands#moduleseed

Fahd Yousri
  • 401
  • 3
  • 12
1

in my case when module in subfolders and want to run in directly without running other seeder

php artisan db:seed --class=WM\Common\Seeder\SmsStatusSeeder  
saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58
0

Use this command

php artisan module:seed <Module Name>