本文整理汇总了PHP中Illuminate\Database\Query\Builder::raw方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::raw方法的具体用法?PHP Builder::raw怎么用?PHP Builder::raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::raw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFullTextSearch
/**
* Parse the fulltext search parameter q
*
* @param string $qParam
* @param array $fullTextSearchColumns
* @return void
*/
protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
{
if ($qParam == '') {
//Add where that will never be true
$this->query->whereRaw('0 = 1');
return;
}
$fulltextType = Config::get('apihandler.fulltext');
if ($fulltextType == 'native') {
//Use pdo's quote method to be protected against sql-injections.
//The usual placeholders unfortunately don't seem to work using AGAINST().
$qParam = $this->query->getConnection()->getPdo()->quote($qParam);
//Use native fulltext search
$this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
//Add the * to the selects because of the score column
if (count($this->query->columns) == 0) {
$this->query->addSelect('*');
}
//Add the score column
$scoreColumn = Config::get('apihandler.fulltext_score_column');
$this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
} else {
$keywords = explode(' ', $qParam);
//Use default php implementation
$this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
foreach ($fullTextSearchColumns as $column) {
foreach ($keywords as $keyword) {
$query->orWhere($column, 'LIKE', '%' . $keyword . '%');
}
}
});
}
}
示例2: raw
/**
* Create a raw database expression.
*
* @param mixed $value
* @return \Illuminate\Database\Query\Expression
* @static
*/
public static function raw($value)
{
return \Illuminate\Database\Query\Builder::raw($value);
}