laravel: function in model must return a relationship instance
I faced that error when I forgot to write return before relation in the model!
check it out now!
I know this has already been answered and accepted. However, if the OP did want to use a property accessor rather than a method use the "get{property name}Attribute" syntax of Laravel to create a custom attribute.
Here is what it would look like for this specific case:
public function getPathAttribute()
{
return App\Helper\GeneralController::getURL($this);
}
using this approach "path" can now be called as an attribute and will not be resolved to a relationship using the syntax:
$article->path;
You need to call it:
$article->path()
When you do $article->path
, you're trying to use Eloquent relationship which you don't have.
You're calling a relationship.
$article->path
To call the method, use '()', like so,
$article->path()