<?php

use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log;

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

//        try {
//
//        } catch (Exception $e) {
//        }

    


        /*if(User::where("name_first", "admin"))
        {
            return;
        }*/


        /**
         * A user is created as the Admin with the below fields.
         * Super User or Admin. Is allowed for all permission and is not to exist in final product release but purely for testing.
         */
        Log::debug("OPRET");
        $user = new \App\User();

        $user->name_first = "admin";
        $user->name_last = "admin";
        $user->email = "admin@admin.local";
        $user->setPasswordAttribute("1234");
        $user->phone = 12345678;


        //gives all permission to the Admin.
        foreach (\Spatie\Permission\Models\Permission::all() as $permission) {
            $user->givePermissionTo($permission);
        }

        $user->save();
    }
}