firstOrFail.js 438 B

1234567891011121314151617181920
  1. 'use strict';
  2. var _require = require('../helpers/is'),
  3. isFunction = _require.isFunction;
  4. module.exports = function firstOrFail(key, operator, value) {
  5. if (isFunction(key)) {
  6. return this.first(key, function () {
  7. throw new Error('Item not found.');
  8. });
  9. }
  10. var collection = this.where(key, operator, value);
  11. if (collection.isEmpty()) {
  12. throw new Error('Item not found.');
  13. }
  14. return collection.first();
  15. };