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/flavourapps.com/leads/leads/app/Imports/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/flavourapps.com/leads/leads/app/Imports/UserImport.php
<?php

namespace App\Imports;

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

class UserImport implements ToModel,WithHeadingRow
{
       
    private $admin_id;

    public function __construct($adminId)
    {
        $this->admin_id = $adminId;
    }

    public function model(array $row)
    {
        //dd($row);
        $user = User::where('id',$this->admin_id)->first();
        $org = Company::where('id',$user->organization_id)->first();
        $mainArray = array();       

		$rowArray = array( 
			"admin_id" => $this->admin_id,
            "name" => $row["name"],
            "email" => $row["email"],
            "mobile" => $row["mobile"],
            "gender" => $row["gender"], 
            "address" => $row["address"],
            "city" => $row["city"],
            "state" => $row["state"],
            "pincode" => $row["pincode"],
            "country" => $row["country"],
            "organization" => $org->company_name,
            "organization_id" => $org->id,
            "type" => "user",                   
            'created_at' => date('Y-m-d H:i:s')
        );  
                   
		array_push($mainArray,$rowArray);

        //dd($mainArray);
        foreach($mainArray as $user)
        {
            
            
            $res = User::create($user);

            if($res)
            {                
                $role = Role::where('slug', "user")->get();
                $res->roles()->attach($role); 
              
            }          

        }
    }
    
}

Anon7 - 2021