The sole()
method will return only one record that matches the criteria. If no such entry is found, then a NoRecordsFoundException
will be thrown. If multiple records are found, then a MultipleRecordsFoundException
will be thrown.
DB::table('products')->where('ref', '#123')->sole();
Tip given by @PascalBaljet