Map existing Database table for Laravel

Sangoku picture Sangoku · Jan 2, 2014 · Viewed 23k times · Source

I am looking for a way to map existing tables in a project with the Eloquent ORM and use them in code. I use a MySQL database and plan to migrate to MSSQL. Any way points are appreciated.

Answer

duellsy picture duellsy · Jan 2, 2014

You'll have to do this manually.

i.e., create an eloquent model for each of the tables you want access to in your code using eloquent.

If you don't have timestamps named created_at and updated_at, in your model you can disable those columns.

Manually

If you have a users table you could 'map' it with a user.php file in your models folder like this

class User extends Eloquent {

    protected $table = 'users';

    public $timestamps = false;

}

Via artisan

You can use Jeffrey Ways Laravel Generators to help streamline the initial creation of your models, however you'll still need to make the timestamp modification manually.