Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel: function in model must return a relationship instance

I try to build a path for a model on laravel

I created a function in my model:

public function path() {     return App\Helper\GeneralController::getURL($this); } 

with dd(App\Helper\GeneralController::getURL($this)) test I got the right answer. (output is a URL)

but in view with the call: $article->path I get this error:

App\Article:: path must return a relationship instance. 

What is wrong?

like image 325
Ali Avatar asked Dec 09 '17 09:12

Ali


1 Answers

You need to call it:

$article->path() 

When you do $article->path, you're trying to use Eloquent relationship which you don't have.

like image 66
Alexey Mezenin Avatar answered Sep 20 '22 09:09

Alexey Mezenin