mercredi 29 novembre 2017

Call to undefined method Illuminate\Database\Query\Builder::attachPermission()

Here's my code for DatabaseSeeder

use Illuminate\Database\Seeder;
use App\User;
use App\Role;
use App\Permission;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
       // $this->call(UsersTableSeeder::class);
       DB::table('users')->delete();
       //1) Create Admin Role
       $role = ['name' => 'super-admin', 'display_name' => 'Super Admin', 'description' => 'Full Permission'];
       $role = Role::create($role);
       //2) Set Role Permissions
       // Get all permission, swift through and attach them to the role
       $permission = Permission::get();
       foreach ($permission as $key => $value) {
           $role->attachPermission($value);
       }
       //3) Create Admin User
       $user = ['name' => 'Super Admin User', 'email' => 'superadminuser@test.com', 'password' => Hash::make('superadmin')];
       $user = User::create($user);
       //4) Set User Role
       $user->attachRole($role);
    }
}

While I'm using below command for db seed i get an error saying Call to undefined method Illuminate\Database\Query\Builder::attachPermission(). I know this is common question in the forum but i don't know what's wrong in my code.

php artisan db:seed --class=DatabaseSeeder



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zQhEky
via IFTTT

Aucun commentaire:

Enregistrer un commentaire