Laravel for Django developers, part 2

By | February 5, 2016

Global functions

I am seeing a lot of framework specific global functions but don’t know where they come from, such as “view()”, “redirect()” etc etc.

ORM

Again, as mentioned in part 1, since we are creating migration files first, then we won’t be able to define FK relationships directly point to another model. According to the “intermediate quickstart” tutorial, you have to be a bit lower level like:

Hang on… Would this create a FK constraint automatically like Django??

Still ORM

Let’s add a few things to this model. First, we will state that the name attribute on the model should be “mass-assignable”. This will allow us to fill the name attribute when using Eloquent’s createmethod:

Hmm, what? Skimming through the tutorial, so this enables you to do this:

Still ORM – take 2

In Django, when you define a ForeignKey like this

You can access the relationship in both ways automatically:

But in Laravel, it seems you have to define the relationship in each model.

Leave a Reply

Your email address will not be published. Required fields are marked *