Am calling function self::func1(self::func2()) from another function create(). it returns a generated code. After execution sometimes it returns as null even though the variable has value. Can anyone help me?
The var_dump($this->randomCode) just before returning function has value. but after that dd($Code) is shown as null.
public function create(){
$Code = self::func1(self::func2());
dd($Code);
}
private function func1($length = 2) {
$this->randomCode = // here i implemented a rand() logic
$codeAlreadyExist = DB::table(self::getTableName())->where('short_code', '=', $this->randomCode)->exists();
if($codeAlreadyExist){
self::func1(self::func2());
} else {
var_dump($this->randomCode);
return $this->randomCode;
}
}
OUTPUT
string(2) "21"
null
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire