> For the complete documentation index, see [llms.txt](https://tobyisme.gitbook.io/laravel/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tobyisme.gitbook.io/laravel/chapter1.md).

# Raw Expressions

有些時候你需要使用raw expression在查詢語劇裡，這樣的表達式會成為字串插入至查詢，因此要小心勿建立任何SQL隱碼攻擊點。要建立raw expression，你可以使用`DB::raw`方法：

## 使用Raw expression

```php
$users = DB::table('users')
                ->select(DB::raw('count(*) as user_count, status'))
                ->where('status', '<>', 1)
                ->groupBy('status')
                ->get();
```

## 衍伸範例

```php
->where(DB::raw('IFNULL(advertsolution_m.start_date,1911/01/01)'),'<=',DATE_FORMAT($now,'Y/m/d'))
```

## 另外的用法

```php
->whereRaw('裡面放sql的語法字串')
```

以上這例子是說當你advertsolution\_m.start\_date的值為null的時後給它ㄧ個預設值1911/01/01，因為Laravel沒有這類的功能，所以我們可以用`DB::raw`。
