Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 2 years ago.
0

Can you show how you are trying to retrieve user city?

You can try namespacing City on the user model too - just so Laravel knows where to find it.

0

Yes, of course. This is my reflection code:

$rc = new \ReflectionClass($model);

if ($rc->hasMethod($fieldName)) {
    // This two calls below are returning: "Relationship method must return 
    // an object of type Illuminate\Database\Eloquent\Relations\Relation"
    $relation = $rc->getMethod('getAttribute')->invoke($model, $fieldName);

    $rc->getMethod($fieldName)->invoke($model);

    // And this one is returning: "Property city does not exist"
    $rp = $rc->getProperty($fieldName);
}

The namespace is not the problem, because without reflection I can access the relationship without any problem. Thanks for your answer!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ablunier ablunier Joined 25 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.