Last active
August 11, 2016 03:13
-
-
Save alexweissman/4abe552d5b52b549101121521fe92c66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function scopeUnionLike($query, $name, $value) | |
| { | |
| $columns = $this->getFillable(); | |
| if (!in_array($name, $columns)) { | |
| throw new \PDOException("Column $name does not exist!"); | |
| } | |
| $subQuery = $query->toSql(); | |
| $result = Capsule::connection($this->connection)->select("select * from ($subQuery) as v WHERE v.$name LIKE :value", [":value" => "$value%"]); | |
| return $result; | |
| } | |
| public function scopeTracks($query) | |
| { | |
| $result = $query | |
| ->select('id', 'php_sid', 'timestamp', 'field_name', 'field_value') | |
| ->unionAll(Capsule::table('cpcrm.web_tracks') | |
| ->select('id', 'php_sid', 'timestamp', 'field_name', 'field_value') | |
| ); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment