<?php

namespace Database\Seeders;

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

class AdminSeeder 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' => Hash::make(config('app.admin_password')),
        'email_verified_at' => Carbon::now()]);
        $user->save();

        $role = Role::firstOrCreate(['name' => 'administrator', 'display_name' => 'Amministratore']);
        $user->assignRole($role);
      }
    }
  }
