Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

This looks like an old post, but it was edited a couple of days ago, so I don't know if the original author is looking for a solution again, but if someone needs this info, here is a packagist package for Laravel 5 to do what you are asking.

Laravel 5 model generator from existing schema: https://packagist.org/packages/ignasbernotas/laravel-model-generator

Hope that helps someone!

There is also a Eloquent Model Generator library. It can be used for generating Eloquent models using database tables as a source. Generated model will include relation methods, docblocks for magic field and relations and several additional properties.

Another here: https://github.com/Xethron/migrations-generator.

You'll only want to use these generators for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php.

For more details look here - https://packagist.org/packages/ignasbernotas/laravel-model-generator#user-content-installation

You can also use SQL Server Migration Assistant (SSMA) to port the database to SQL Server, but you will still need to write your own models to match the schema.

http://blogs.msdn.com/b/ssma/ http://www.microsoft.com/en-us/download/details.aspx?id=43688

Still this might help get halfway there, from both sides of the puzzle.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top