public function create($amount = 1, $reward = null, array $data = [], $expires_in = null, $is_disposable = false)
    {
        $records = [];

        foreach ($this->output($amount) as $code) {
            $records[] = [
                'code' => $code,
                'reward' => $reward,
                'data' => json_encode($data),
                'expires_at' => $expires_in ? Carbon::now()->addDays($expires_in) : null,
                'is_disposable' => $is_disposable,
            ];
        }

        if (Promocode::insert($records)) {
            return collect($records)->map(function ($record) {
                $record['data'] = json_decode($record['data'], true);

                return $record;
            });
        }

        return collect([]);
    }
public function create($amount = 1, $reward = null, array $data = [], $expires_in = null, $is_disposable = false)
    {
        $records = [];

        foreach ($this->output($amount) as $code) {
            $records[] = [
                'code' => $code,
                'reward' => $reward,
                'data' => json_encode($data),
                'expires_at' => $expires_in ? Carbon::now()->addDays($expires_in) : null,
                'is_disposable' => $is_disposable,
            ];
        }

        if (Promocode::insert($records)) {
            return collect($records)->map(function ($record) {
                $record['data'] = json_decode($record['data'], true);

                return $record;
            });
        }

        return collect([]);
    }
public function create ( $ amount = 1 , $ reward = null , array $ data = [ ] , $ expires_in = null , $ is_disposable = false ) { $ records = [ ] ; foreach ( $ this -> output ( $ amount ) as $ code ) { $ records [ ] = [ 'code' => $ code , 'reward' => $ reward , 'data' => json_encode ( $ data ) , 'expires_at' => $ expires_in ? Carbon :: now ( ) -> addDays ( $ expires_in ) : null , 'is_disposable' => $ is_disposable , ] ; } if ( Promocode :: insert ( $ records ) ) { return collect ( $ records ) -> map ( function ( $ record ) { $ record [ 'data' ] = json_decode ( $ record [ 'data' ] , true ) ; return $ record ; } ) ; } return collect ( [ ] ) ; }
Save promocodes into database
Successful insert returns generated promocodes
Fail will return empty collection.

@param int $amount
@param null $reward
@param array $data
@param int|null $expires_in
@param bool $is_disposable

@return \Illuminate\Support\Collection
Save promocodes into database Successful insert returns generated promocodes Fail will return empty collection .