QE
QE is a helper class that makes writing complex SQL queries in Laravel simpler. It gives you a lot of functions for things you often need in databases. Here are QE's functions:
1. Basic Functions
c(string $name): Gets a reference to a specific database column.raw(string $sql, array $bindings = []): Represents a raw SQL expression. Good for when you need something special.
2. Advanced Expressions
case(): Handles conditional logic.coalesce(...$parameters): Picks the first non-null value from a list.exists(QueryBuilder|EloquentBuilder $query): Checks if a subquery has any results.if(DBFunction $condition, $valueIfTrue, $valueIfFalse): Does something if a condition is true, and something else if false.isNull($parameter): Checks if a value is empty.
3. Conditional Operators
condition(mixed $parameter1, string $operator = null, mixed $parameter2 = null): Creates a condition.- [
and(...$parameters)]: Combi(Conditional/and.md)nes conditions with AND. - [
or(...$parameters)]: Combi(Conditional/or.md)nes conditions with OR. not($parameter): Negates a condition.
4. Date Functions
Working with dates made easy.
addDate($subject, $value, Date\Unit $interval = Date\Unit::DAY): Adds a specific value to a date/datetime.currentDate(): Retrieves the current date.currentTime(): Retrieves the current time.date($parameter): Extracts the date part from a datetime expression.dateDiff($date1, $date2): Returns the number of days between two date values.dayOfWeek($parameter): Returns the weekday index for a given date/datetime.hour($parameter): Returns the hour part for a given time/datetime.minute($parameter): Returns the minute part for a given time/datetime.month($parameter): Returns the month part for a given date/datetime.monthName($parameter): Returns the name of the month for a given date/datetime.now(): Returns the current date and time.second($parameter): Returns the seconds part of a time/datetime.subDate($subject, $value, Date\Unit $interval = Date\Unit::DAY): Subtracts a time/date interval from a date and then returns the date.time($parameter): Extracts the time part from a given time/datetime.year($parameter): Returns the week number for a given date/datetime.
5. Numeric Functions
Performing math operations and dealing with numbers.
abs($parameter): Returns the absolute value of a number.acos($parameter): Returns the arc cosine of a number.add(...$parameters): Adds multiple numeric parameters.asin($parameter): Returns the arc sine of a number.atan($parameter): Returns the arc tangent of a number.- [
atan2($y, $x)]:(Numeric/atan2.md) Returns the arc tangent of two numbers. avg($parameter): Returns the average value of an expression.ceil($parameter): Returns the smallest integer value that is >= to a number.cos($parameter): Returns the cosine of a number.cot($parameter): Returns the cotangent of a number.count($parameter): Returns the number of records returned by a select query.degreesToRadian($parameter): Converts a degree value into radians.divide(...$parameters): Divide the first numeric parameter by subsequent numeric parameters.exp($parameter): Returns e raised to the power of a specified number.floor($parameter): Returns the largest integer value that is <= to a number.greatest(...$parameters): Returns the greatest value of the list of arguments.least(...$parameters): Returns the smallest value of the list of arguments.ln($parameter): Returns the natural logarithm of a number.log($number, $base = 2): Returns the natural logarithm of a number, or the logarithm of a number to a specified base.max($parameter): Returns the maximum value in a set of values.min($parameter): Returns the minimum value in a set of values.mod($x, $y): Returns the remainder of a number divided by another number.multiply(...$parameters): Multiply multiple numeric parameters.pi(): Returns the value of PI.pow($x, $y): Returns the value of a number raised to the power of another number.radianToDegrees($parameter): Converts a value in radians to degrees.rand($seed = null): Returns a random number.round($parameter, $decimals = 0): Rounds a number to a specified number of decimal places.sign($parameter): Returns the sign of a number.sin($parameter): Returns the sine of a number.sqrt($parameter): Returns the square root of a number.subtract(...$parameters: Subtracts multiple numeric parameters.sum($parameter): Calculates the sum of a set of values.tan($parameter): Returns the tangent of a number.
6. String Functions
Manipulating text has never been simpler.
concat(...$parameters): Adds two or more expressions together.concatWS($separator, ...$parameters): Adds two or more expressions together with a separator.contains($haystack, $needle): Determines if a given string contains a given substring.endsWith($haystack, $needle): Determines if a given string ends with a given substring.left($string, $numberOfChars): Extracts a number of characters from a string (starting from left).length($parameter): Returns the length of a string.lower($parameter): Converts a string to lower-case.padLeft($string, $length, $pad = ' '): Left-pads a string with another string, to a certain length.ltrim($parameter): Removes leading spaces from a string.padRight($string, $length, $pad = ' '): Right-pads a string with another string, to a certain length.position($subString, $string): Finds the position of a substring within a string.repeat($parameter, $number): Repeats a string a specified number of times.replace($string, $substring, $newString): Replaces occurrences of a substring with a new string.reverse($parameter): Reverses the characters of a string.right($string, $numberOfChars): Extracts a number of characters from a string (starting from right).rtrim($parameter): Removes trailing spaces from a string.space($parameter): Returns a string consisting of a specified number of spaces.startsWith($haystack, $needle): Determines if a given string starts with a given substring.substr($string, $start, $length = null): Extracts a substring from a string starting at a specified position with optional length.trim($parameter): Removes leading and trailing spaces from a string.upper($parameter): Converts a string to upper-case.