beyondcode / invoker-community

74 stars 2 forks source link

Unable to resolve the related model for relation: Supplier #311

Closed tobya closed 1 year ago

tobya commented 1 year ago

I am unsure why this error prevents the page from loading.

OS: win32 Invoker Version: 2.9.0 Laravel Version: 8.83.16 Local project: unknown PHP Binary: C:\Development\php\php81\php.exe Route: /project/index?class=App%5CModels%5COrder&time=1664022268015&project=remote-sjmNHnbJeJs26eY1126i5V

Error:

Exception 

  Unable to resolve the related model for relation: Supplier
Please add @relatedModel doc block.

  at phar:///tmp/forge_invoker.phar/src/Factories/RelatedModelItem.php:43
     39▕         $phpdoc = new \_HumbugBoxf4b902e0e9ad\Barryvdh\Reflection\DocBlock($reflection, $context);
     40▕         if ($phpdoc->hasTag('relatedModel')) {
     41▕             $model = $phpdoc->getTagsByName('relatedModel')[0]->getContent();
     42▕         } else {
  ➜  43▕             throw new \Exception('Unable to resolve the related model for relation: ' . $reflection->getName() . '
     44▕ Please add @relatedModel doc block.');
     45▕         }
     46▕         return $model;
     47▕     }

  1   phar:///tmp/forge_invoker.phar/src/Factories/RelatedModelItem.php:31
      _HumbugBoxf4b902e0e9ad\Invoker\Factories\RelatedModelItem::getRelatedModelFromDocBlock()

  2   phar:///tmp/forge_invoker.phar/src/Factories/RelatedModelItem.php:23
      _HumbugBoxf4b902e0e9ad\Invoker\Factories\RelatedModelItem::getRelatedModel()
mpociot commented 1 year ago

As the error suggests (even though not super clear 😅 ) you need to add a @relatedModel docblock to the relation method.

Something like this:

/**
 * @relatedModel \App\Models\User
 */
public function myRelation()
{
    return $this->belongsTo($customClass);
}