Skip to content
Advertisement

How to correctly specify the relationships between Eloquent Models

I have the following Models

ReleasePackages

JavaScript

and Users

JavaScript

Now for each release package, there are two columns which is related with Users. One is created_by and the other is approved_by. I am trying to set this relation by the the above code, but when I call

$packages = ReleasePackages::with(['artifacts','created_by','approved_by'])->get();

I am not getting the relations with Users. I have the corresponding user id in users table and the column name is id. I am getting the following response from the above controller code :

JavaScript

how can I change the code to make the relationships works correctly ?

Advertisement

Answer

Your relationship wrong for created_by() and approved_by() it should be belongsTo

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement