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()'))
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
I found a partial solution, but if anyone has any ideas that work better, I'm eager to hear them (it seems the original Capsule package actually had support built in, maybe it was lost when it was merged, or maybe I'm using it incorrectly?)
use Illuminate\Database\Capsule\Manager as Capsule;
$connection = Capsule::connection();
// You can now use $connection->raw() in place of DB::raw()
...->orderBy($connection->raw('RAND()'))