No, it does not matter if a column is not specified as a foreign key on the table. Showing some of your code would be helpful in order to resolve your errors.
Laravel Nova\Eloquent Relationships
Hi,
I am working on a project, and the other guy that created the migrations, didn't specify the foreign keys of the tables, he just created them as integers.
As of now, I am trying to intagrate laravel nova, and it is throwing some errors on the relationships part. Is it possible that eloquent relationships don't work if the fk is assigned as int and not as foreign key?
@Kris01 This is likely because the field on your model is the same name as the relationship. If owner is really the foreign key on your table you should try to rename your relationship to ownerUser to see if that works.
public function ownerUser() {
return $this->belongsTo('App\Models\User', 'owner', 'id');
}
Your Nova field would have to be updated as well
BelongsTo::make('owner', 'ownerUser', \App\Nova\User::class)
However, I strongly recommend naming your foreign key owner_id to avoid naming collisions.
Please or to participate in this conversation.