Count Vs Exists (ARCH7063)
هذا المحتوى غير متوفر بلغتك بعد.
Key php.orm.count-vs-exists · Severity info · Category orm
Using count() > 0 to test whether a row exists forces the database to count every match. A cheaper exists() short-circuits at the first row.
Incorrect
Section titled “Incorrect”<?phpif (User::where('email', $email)->count() > 0) { // counts every match}Correct
Section titled “Correct”<?phpif (User::where('email', $email)->exists()) { // stops at the first row}Use exists() for presence checks instead of count() > 0.