KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/leadai/webmaster.leadai.co.in/app/Imports/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/leadai/webmaster.leadai.co.in/app/Imports/ClientImport.php
<?php

namespace App\Imports;

use App\Models\SoftwareClient;
use App\Models\Role;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class ClientImport implements ToModel,WithHeadingRow
{
    private $admin_id;
    

    public function model(array $row)
    {
        //dd($row);
        $this->admin_id = session()->get('loggedIn')['id'];
        $mainArray = array();       
        
		$rowArray = array( 
			"admin_id" => $this->admin_id,
			"name"	=> $row['name'],  
			"mobile" => $row['mobile'],  
			"email" => $row['email'],
            "password"=>$row['password'],
            "designation" =>$row['designation'],
            "department" =>$row['department'],
            "address" =>$row['address'],
            "city" =>$row['city'],
            "state" =>$row['state'],
            "country" =>$row['country'],
            "pincode" =>$row['pincode'],
            "status" => 1,
            "type" => "employee",           
            'created_at'=>date('Y-m-d H:i:s')
        );  
                   
		array_push($mainArray,$rowArray);

        //dd($mainArray);
        foreach($mainArray as $emp)
        {
            
            $emp["password"] = Hash::make($emp["password"]);
            $res = User::create($emp);

            if($res)
            {
                    
                $u = User::where('id', $res->id)->first();
                $role = Role::where('slug', "employee")->where('admin_id', $this->admin_id)->get();
                $u->roles()->attach($role);   
              
            }
            

        }
    }
    
}

Anon7 - 2021