dongtuwu8548
2013-10-01 07:47
浏览 37
已采纳

Laravel 4 DB:在框架外运行时,raw()不可用

I'm using the [illuminate/database component][1] from Laravel 4 through composer - and while it generally works well, the DB facade seems to be broken in this standalone version. This meant I was unable to use static functions such as DB::raw(). It seems like the DB facade is even included in the package, but it doesn't work with ::raw().

I'm trying to do something like this -

...->orderBy(DB::raw('RAND()'))

图片转代码服务由CSDN问答提供 功能建议

我正在使用Laravel 4中的[照亮/数据库组件] [1]到作曲家 - 虽然它一般 运行良好,数据库外观似乎在这个独立版本中被打破。 这意味着我无法使用DB :: raw()等静态函数。 看起来数据库外观甚至包含在包中,但它不适用于:: raw()。

我正在尝试这样做 -

  ...-> orderBy(DB :: raw('RAND  ()'))
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsgd4654674 2015-03-24 08:55
    已采纳

    Capsule::raw() is available, and is linked to the default connection's raw().

    Also, what I did is I created a class:

    /**
     * @method static raw($value)
     * @method static array select($query, $bindings = [], $useReadPdo = true)
     * ...etc.
     */
    class DB extends Manager
    {
    }
    

    so that

    1. You can use DB::raw().
    2. IDE code completion works.
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题