Eloquent Collection: Counting and Detect Empty
问题 This may be a trivial question but I am wondering if Laravel recommends a certain way to check whether an Eloquent collection returned from $result = Model::where(...)->get() is empty, as well as counting the number of elements. We are currently using !$result to detect empty result, is that sufficient? As for count($result) , does it actually cover all cases, including empty result? 回答1: When using ->get() you cannot simply use any of the below: if (empty($result)) { } if (!$result) { } if (