Illuminate\Database\Query\Builder::dynamicWhere PHP Method

dynamicWhere() public method

Handles dynamic "where" clauses to the query.
public dynamicWhere ( string $method, string $parameters )
$method string
$parameters string
    public function dynamicWhere($method, $parameters)
    {
        $finder = substr($method, 5);
        $segments = preg_split('/(And|Or)(?=[A-Z])/', $finder, -1, PREG_SPLIT_DELIM_CAPTURE);
        // The connector variable will determine which connector will be used for the
        // query condition. We will change it as we come across new boolean values
        // in the dynamic method strings, which could contain a number of these.
        $connector = 'and';
        $index = 0;
        foreach ($segments as $segment) {
            // If the segment is not a boolean connector, we can assume it is a column's name
            // and we will add it to the query as a new constraint as a where clause, then
            // we can keep iterating through the dynamic method string's segments again.
            if ($segment != 'And' && $segment != 'Or') {
                $this->addDynamic($segment, $connector, $parameters, $index);
                $index++;
            } else {
                $connector = $segment;
            }
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Handles dynamic "where" clauses to the query.
  *
  * @param string $method
  * @param string $parameters
  * @return $this 
  * @static 
  */
 public static function dynamicWhere($method, $parameters)
 {
     return \Illuminate\Database\Query\Builder::dynamicWhere($method, $parameters);
 }