Laravel
  • Introduction
  • 常用語法
  • 結合Vue.js從無到有架設一個網站
  • 透過CMD新增File
  • Schedule
  • Annotation
  • Super Variable
  • API的設定
  • Create 新專案
  • Raw Expressions
  • Import - Export
  • JWT 外加 登入功能
  • Carbon
  • Storage 保存文件
  • Require_once
  • 設定apache將laravel專案run起來
  • 有關leftjoin的用法
  • Advanced Join Clauses
  • Call API方式
  • 產生新的APP_KEY
  • 程序優化技巧
  • composer update VS 手動丟檔
  • 全域變數被使用過
  • FB的SDK
Powered by GitBook
On this page
  • 使用Raw expression
  • 衍伸範例
  • 另外的用法

Was this helpful?

Raw Expressions

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

使用Raw expression

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

衍伸範例

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

另外的用法

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

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

PreviousCreate 新專案NextImport - Export

Last updated 5 years ago

Was this helpful?