<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Carbon\Carbon;
use App\Models\Role;
// use Spatie\Permission\Models\Role;
use Hash;

class AdminSeed extends Seeder
{
  /**
  * Run the database seeds.
  *
  * @return void
  */
  public function run()
  {
    $user = \App\Models\User::where('email', config('app.admin_email'))->first();
    if($user == null){
      $user = \App\Models\User::create([
        'nome' => 'Admin',
        'cognome' => 'Admin',
        'email' => config('app.admin_email'),
        'password' => bcrypt(config('app.admin_password')),
        'email_verified_at' => Carbon::now()]);

        $user->save();

      }
      $role = Role::firstOrCreate(['name' => 'superadmin', 'display_name' => 'SuperAdmin']);
      $user->roles()->detach();
      $user->assignRole($role);

    }
  }
