Laravel 4: how to run a raw SQL?

In the Laravel 4 manual – it talks about doing raw commands like this:

DB::select(DB::raw('RENAME TABLE photos TO images'));

edit: I just found this in the Laravel 4 documentation which is probably better:

DB::statement('drop table users');

Update: In Laravel 4.1 (maybe 4.0 – I’m not sure) – you can also do this for a raw Where query:

$users = User::whereRaw('age > ? and votes = 100', array(25))->get();

Further Update If you are specifically looking to do a table rename – there is a schema command for that – see Mike’s answer below for that.

Leave a Comment