<?php

use Illuminate\Database\Seeder;

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;

class PermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
      // Reset cached roles and permissions
      app()['cache']->forget('spatie.permission.cache');

      //Permission list
      Permission::create(['name' => 'dashboard.index']);

      Permission::create(['name' => 'users.index']);
      Permission::create(['name' => 'users.store']);
      Permission::create(['name' => 'users.update']);
      Permission::create(['name' => 'users.destroy']);

      Permission::create(['name' => 'views.reports']);

      //Admin
      $admin = Role::create(['name' => 'Admin']);
      $admin->givePermissionTo(Permission::all());

      //Guest
      $guest = Role::create(['name' => 'Guest']);

      $guest->givePermissionTo([
        'dashboard.index'
      ]);

      //User Admin
      $user = User::find(1); //Admin
      $user->assignRole('Admin');

    }
}
