Skip to content

Instantly share code, notes, and snippets.

@alexweissman
Last active August 11, 2016 03:13
Show Gist options
  • Select an option

  • Save alexweissman/4abe552d5b52b549101121521fe92c66 to your computer and use it in GitHub Desktop.

Select an option

Save alexweissman/4abe552d5b52b549101121521fe92c66 to your computer and use it in GitHub Desktop.
<?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