Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looking at the Laravel site, I’m concerned about Laravel’s reliance on an ORM. Not only because ORMs are widely derided, but because I have a legacy MySQL DB and PHP 5 project I want to resurrect. I’m down to rewrite the server, but how do I restore a database full of user data with Laravel?


I work on a project like this and you'll run into some papercuts, but it's not hard.

You can take a model for anything in your legacy code, and just set properties on the model to teach Laravel how to deal with things that don't follow conventions.

For example, you can override the table name. Suppose you had a legacy table called "postdata". In Laravel, this table would be called posts, and a model would be Post.

So you'd just tell Post to query postdata rather than posts.

Likewise, you can tell it which fields to cast as dates, booleans, etc. You can tell it which fields represent timestamps for updating, creating, deleting and so forth.

You can setup relations that don't follow naming conventions the same way.

The only issue I've run into is doing things like setting up relationships across databases. You can do it, it's just not super straightforward.

I think you'll find it's a breath of fresh air to have a modern wrapper around your legacy code, and that your legacy stuff will then fit in quite nicely with your new work.


Great, thanks! I’m pretty psyched to get started, after reading these comments.


Laravel is “linked” together via a combination of Composer dependency manager and Dependency Injection. You can easily customize your setup to remove the dependency on Eloquent ORM and use something else.


Thanks!


What I'm doing is recreate everything the Laravel way and worry about importing the data (millions of pictures, videos and comments) later. I figured that once I'm proficient at Laravel that writing some import jobs would be relatively easy.


Thanks! That’s happens to be just what I need to do: import pictures and related data.


Does your DB have a classic design? You can very easily map an existing DB with a fresh Laravel install, just write a couple Models, their relationships and you're almost set.

I have been working with Laravel on a daily basis since 6 years and have never felt more efficient with code.


Not sure what you mean by classic, but I designed it manually to be queried with plain SQL. So I suspect the answer to your question is yes.

Thanks for the info!


By classic I mean something somewhat standardized like user table: id, name, email ; post table: id, user_id, content etc.


Pretty much, then, yes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: