HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Library/CouponLibrary.php
<?php 
namespace App\Library;

use App\Coupon;
use Illuminate\Support\Str;

class CouponLibrary {
	public function generateRandomCodes($coupon, $number, $type,$id) {
		if(empty($coupon))
	    	$code = Str::random($number);
	    else
	    	$code = $coupon;

	    if($type == 'insert')
	    	$affected = Coupon::where('code', $code)->get();
	    else
	    	$affected = Coupon::where('code', $code)->where('id','!=',$id)->get();

	    if ($affected->count() > 0) {
	    	if(!empty($coupon)) {
	    		return 'coupon_code_exceed';
	    	}
	    	else
	        	$this->generateRandomCodes($coupon, $number);
	    }
	    return $code;
	}
}