MOON
Server: Apache
System: Linux host.sunshiene.com 4.18.0-553.121.1.el8_10.x86_64 #1 SMP Thu Apr 30 09:06:34 EDT 2026 x86_64
User: clientsoftwares (1005)
PHP: 8.2.31
Disabled: system, exec, mail, shell_exec, passthru, popen, proc_open, pcntl_exec, dl, ini_alter, ini_restore, symlink, link, chown, posix_kill
Upload Files
File: /home/clientsoftwares/public_html/stocky.clientsoftwares.com/app/Imports/BrandImport.php
<?php

namespace App\Imports;

use App\Models\Brand;
use Examyou\RestAPI\Exceptions\ApiException;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\ToArray;
use Illuminate\Support\Str;

class BrandImport implements ToArray, WithHeadingRow
{
	public function array(array $brands)
	{
		DB::transaction(function () use ($brands) {

			foreach ($brands as $brand) {

				if (
					!array_key_exists('name', $brand)
				) {
					throw new ApiException('Field missing from header.');
				}

				$brandName = trim($brand['name']);
				$brandCount = Brand::where('name', $brandName)->count();
				if ($brandCount > 0) {
					throw new ApiException('Brand ' . $brandName . ' Already Exists');
				}

				$newBrand = new Brand();
				$newBrand->name = $brandName;
				$newBrand->slug = Str::slug($brandName, '-');
				$newBrand->save();
			}
		});
	}
}