Laravel, do..while loop loops infinitely?
Try using $data->count()
to check if anything were returned in the result set:
do {
$testvar = Str::random(5);
$data = User::where('password_url', 'LIKE', '%'.$testvar.'%')->get();
}
while ($data->count());
You can do using below code too:
do {
$testvar = Str::random(5);
$data = User::where('password_url', 'LIKE', '%'.$testvar.'%')->get();
}while (count($data)!=0);
Why i am suggesting this, is because sometimes $data->count() return wrong count!!
(It has happened to me so at that time i used count() function and it worked!
Have you tried this,
do{
$testvar = Str::random(5);
$data = User::where('password_url', 'LIKE', '%'.$testvar.'%')->get();
}while (!empty($data->count()));