/** * Determines the parameters and calls Where with a property in the method name * * @param array $arguments * @param array &$parts * * @return $this * @throws InvalidArgumentException */ private function runWhereWithPropertyMethod(array $arguments, array &$parts) { if (count($arguments) !== 1) { throw new InvalidArgumentException("You must pass a value for the property to filter the results."); } $parts = array_pad($parts, 3, null); $property = $parts[2]; $value = $arguments[0]; $logical = $parts[1]; foreach ($this->filter->getOperators() as $operator => $description) { if (ends_with($property, $description)) { // Remove description off of the end of the property $property = str_replace($description, '', $property); $this->filter = $this->filter->where($property, $value, $operator, $logical); return $this; } } // Default to equals $this->filter = $this->filter->where($property, $value, '=', $logical); return $this; }
/** * @test * @expectedException InvalidArgumentException */ public function it_raises_an_exception_when_building_where_raw_with_an_unknown_logical() { $this->filter->whereRaw("condition = value'", 'xor'); }