B
B
BonBon Slick2017-07-11 19:37:39
Laravel
BonBon Slick, 2017-07-11 19:37:39

Laravel belongsTo via pivot table?

public  function referralTo()
    {
        $isReferraled = UserReferral::where('referral_id', $this->id)->first()->inviter;
            return $isReferraled;
    }

Will give an error:
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

Therefore, it is necessary to somehow pull out the user who invited the current one in a standard way. Communication goes one to one, and it is necessary to use the intermediate table. Now I have it as a table of the UserReferrals model, I specifically made it as a model, for the example above, alas, it did not work.
How to use pivot table when Laravel ORM belongsTo?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2017-07-11
@Alex_Wells

"Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation"
Have you read this at all? Where do you have a relationship method in that code? In one single place: ->inviter.
Relationship method must RETURN - this is required from the method, and therefore from you. Where is the method? In the UserReferral model, where else could it be. Show the inviter method code from this model.
Is it really so difficult to follow what is required of you in plain text. Moreover, the 100% stacktrace even indicates a specific place, and with the new laravel 5.5 whoops, the code is also there ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question