public function validate($voucher_code = 0) { if (!$voucher_code) { return false; } $return = []; $query = Voucher::query(); $query->where('code', $voucher_code); $query->select('code', 'value', 'operation', 'status', 'date_expired'); $voucher = $query->first(); /* ** Check if voucher is exist */ if ($voucher) { /* ** Check voucher status is usable */ if ($voucher->status == false) { return false; } /* ** Check voucher expiry */ if ($voucher->date_expired >= Carbon::now()) { $this->code = $voucher_code; $this->voucher = $voucher; return true; } return false; } return false; }
public function search($input) { $query = Voucher::query(); $columns = Schema::getColumnListing('vouchers'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }