Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property: App\Models\.... on line 101 in ...\lluminate\Database\Eloquent\Relations\BelongsTo.php #35

Closed
c-myers1 opened this issue Nov 18, 2020 · 2 comments

Comments

@c-myers1
Copy link

With the command

php artisan laracrud:controller Issuance --api

I'm getting the error:

Undefined property: App\Models\Issuance::$weeklynetorderid on line 101 in C:\xampp2\htdocs\myapp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\BelongsTo.php

weeklynetorderid is the foreign key pointing to an id column in another table. The function within the Issuance model is

public function weeklynetorderid()
{
    return $this->belongsTo(WeeklyNetorder::class,'weeklynetorderid');
}

I generated WeeklyNetorder model already which is being referred to.

My searches for this error seems to indicate when there is confusion between weeklynetorderid as a function or as a property but it hasn't made a solution clearer to me.

How can I troubleshoot?

@c-myers1
Copy link
Author

Ok, seems to be a Laravel issue as per this.

@digitaldreams
Copy link
Owner

Hi @c-myers1
Its not a laravel issue. Let me explain what was wrong on your above code.
You can't your belongsTo method name same as your foreign key name.
Here your belongsTo method name weeklynetorderid and foreign key weeklynetorderid which is same name.

Rename your belongsTo method name weeklynetorder instead of weeklynetorderid will solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants